Skip to content

Commit

Permalink
修复 当输入平滑延迟为0报错
Browse files Browse the repository at this point in the history
修复 搜索框性能
新增 支持快捷方式参数
  • Loading branch information
MakesYT committed Nov 2, 2023
1 parent f3ede64 commit 2264c4d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 15 deletions.
23 changes: 22 additions & 1 deletion Core/SDKs/Tools/AppTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ public static async Task AppSolverA(Dictionary<string, SearchViewItem> collectio
var data = new WIN32_FIND_DATA();
//((IShellLinkW)link).GetShowCmd
((Shell32.IShellLinkW)link).GetPath(sb, sb.Capacity, out data, 0);
var argSb = new StringBuilder(260);
link.GetArguments(argSb, argSb.Capacity);
var arg = argSb.Length > 0 ? argSb.ToString() : null;
if (arg != null && arg.Contains("%"))
{
Regex regex = new Regex("%(\\w+)%");

// 替换后的字符串
arg = regex.Replace(arg, match =>
{
// 获取匹配到的环境变量名称
var variable = match.Groups[1].Value;
// 获取环境变量值
var value = Environment.GetEnvironmentVariable(variable);
// 返回替换后的值
return value;
});
}

var targetPath = sb.ToString() ?? file;

Expand Down Expand Up @@ -393,7 +414,7 @@ public static async Task AppSolverA(Dictionary<string, SearchViewItem> collectio
collection.TryAdd(refFileInfo.FullName, new SearchViewItem
{
Keys = keys, IsVisible = true, FileInfo = refFileInfo, FileName = localName,
OnlyKey = refFileInfo.FullName, IsStared = star,
OnlyKey = refFileInfo.FullName, IsStared = star, Arguments = arg,
FileType = FileType.应用程序, Icon = null
});
}
Expand Down
9 changes: 7 additions & 2 deletions Core/SDKs/Tools/DelayAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace Core.SDKs.Tools;

public class DelayAction
{
private readonly object _lock1 = new();
private Timer? _timerDbc;
private static readonly ILog Log = LogManager.GetLogger(nameof(DelayAction));
private readonly object _lock1 = new();
private bool _needDelay = false;
private Timer? _timerDbc;

/// <summary>
/// 延迟timesMs后执行。 在此期间如果再次调用,则重新计时
Expand All @@ -29,6 +29,11 @@ public void Debounce(int timeMs, TaskScheduler invoker, Action action)
{
Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, invoker);
//Log.Debug("完成"+timeMs);
if (timeMs == 0)
{
return;
}

_timerDbc = new Timer(timeMs);
_timerDbc.AutoReset = false;
_needDelay = false;
Expand Down
17 changes: 9 additions & 8 deletions Core/ViewModel/SearchWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ namespace Core.ViewModel;
public partial class SearchWindowViewModel : ObservableRecipient
{
private static readonly ILog Log = LogManager.GetLogger(nameof(SearchWindowViewModel));
private static readonly List<SearchViewItem> TempList = new(1000);
public readonly Dictionary<string, SearchViewItem> _collection = new(400); //存储本机所有软件
private readonly TaskScheduler _scheduler = TaskScheduler.FromCurrentSynchronizationContext();

private readonly DelayAction _searchDelayAction = new();

[ObservableProperty] private bool? _everythingIsOk = true;
private static readonly List<SearchViewItem> TempList = new(1000);

[ObservableProperty] private BindingList<SearchViewItem> _items = new(TempList); //搜索界面显示的软件

Expand All @@ -39,6 +42,10 @@ public partial class SearchWindowViewModel : ObservableRecipient

[ObservableProperty] private int? _selectedIndex = -1;


private bool nowInSelectMode = false;
private Action<SearchViewItem> selectAction;

public SearchWindowViewModel()
{
ReloadApps(true);
Expand Down Expand Up @@ -273,6 +280,7 @@ private void LoadLast()
private void GetIconInItemsAsync(SearchViewItem t)
{
//Log.Debug($"为{t.OnlyKey}生成Icon");

switch (t.FileType)
{
case FileType.文件夹:
Expand Down Expand Up @@ -321,9 +329,6 @@ private void GetIconInItemsAsync(SearchViewItem t)
//
}

private readonly DelayAction _searchDelayAction = new();
private readonly TaskScheduler _scheduler = TaskScheduler.FromCurrentSynchronizationContext();

// ReSharper disable once RedundantAssignment
partial void OnSearchChanged(string? value)
{
Expand Down Expand Up @@ -616,10 +621,6 @@ partial void OnSearchChanged(string? value)
});
}


private bool nowInSelectMode = false;
private Action<SearchViewItem> selectAction;

public void SetSelectMode(bool flag, Action<SearchViewItem> action)
{
nowInSelectMode = flag;
Expand Down
6 changes: 6 additions & 0 deletions PluginCore/SearchViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public FileInfo? FileInfo
get;
}

public string? Arguments
{
set;
get;
}

public DirectoryInfo? DirectoryInfo
{
set;
Expand Down
14 changes: 12 additions & 2 deletions uToolkitopia/Services/SearchItemTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ public void OpenSearchItem(SearchViewItem searchViewItem)
searchViewItem.Action?.Invoke(searchViewItem);
break;
default:
Shell32.ShellExecute(IntPtr.Zero, "open", searchViewItem.OnlyKey, "", "",
ShowWindowCommand.SW_NORMAL);
if (searchViewItem.Arguments == null)
{
Shell32.ShellExecute(IntPtr.Zero, "open", searchViewItem.OnlyKey, "", "",
ShowWindowCommand.SW_NORMAL);
}
else
{
Shell32.ShellExecute(IntPtr.Zero, "open", searchViewItem.OnlyKey, searchViewItem.Arguments,
"",
ShowWindowCommand.SW_SHOWNORMAL);
}

break;
}

Expand Down
3 changes: 2 additions & 1 deletion uToolkitopia/View/SearchWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
Visibility="{Binding EverythingIsOk, Converter={StaticResource reverseBoolToVisibilityConverter}}"
IsClosable="False" />
<ListBox x:Name="dataGrid" MaxHeight="415"
ItemsSource="{Binding Items,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Items}"
VirtualizingStackPanel.IsVirtualizing="True"

Margin="0,0,0,0">
<ListBox.ItemContainerStyle>
Expand Down
5 changes: 4 additions & 1 deletion uToolkitopia/View/SearchWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ protected override void OnSourceInitialized(EventArgs e)
}


private void w_Deactivated(object sender, EventArgs e) => Visibility = Visibility.Hidden;
private void w_Deactivated(object sender, EventArgs e)
{
Visibility = Visibility.Hidden;
}

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetFocus(IntPtr hWnd);
Expand Down

0 comments on commit 2264c4d

Please sign in to comment.