resolve short freeze issue with no icon preview option

This commit is contained in:
Victor Lin 2022-01-23 18:40:21 +08:00
parent 0c05b5f363
commit ef2c587af8
7 changed files with 46 additions and 21 deletions

View File

@ -7,7 +7,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Community.PowerToys.Run.Plugin.Everything</RootNamespace> <RootNamespace>Community.PowerToys.Run.Plugin.Everything</RootNamespace>
<AssemblyName>Community.PowerToys.Run.Plugin.Everything</AssemblyName> <AssemblyName>Community.PowerToys.Run.Plugin.Everything</AssemblyName>
<Version>0.0.2.1</Version> <Version>0.0.2.5</Version>
<useWPF>true</useWPF> <useWPF>true</useWPF>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
@ -16,8 +16,8 @@
<Authors>Yu Chieh (Victor) Lin</Authors> <Authors>Yu Chieh (Victor) Lin</Authors>
<Company /> <Company />
<Product /> <Product />
<AssemblyVersion>0.0.2.1</AssemblyVersion> <AssemblyVersion>0.0.2.5</AssemblyVersion>
<FileVersion>0.0.2.1</FileVersion> <FileVersion>0.0.2.5</FileVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -103,10 +103,10 @@
<None Update="Everything64.dll"> <None Update="Everything64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Everything64nolock.dll"> <None Update="Images\Everything.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Images\Everything.dark.png"> <None Update="Images\Everything.ico.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Images\Everything.light.png"> <None Update="Images\Everything.light.png">

BIN
Images/Everything.ico.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

27
Main.cs
View File

@ -26,9 +26,11 @@ namespace Community.PowerToys.Run.Plugin.Everything
{ {
private const string Wait = nameof(Wait); private const string Wait = nameof(Wait);
private const string Top = nameof(Top); private const string Top = nameof(Top);
private const string NoPreview = nameof(NoPreview);
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$"; private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
private bool _wait; private bool _wait;
private bool _top; private bool _top;
private bool _noPreview;
public string Name => Resources.plugin_name; public string Name => Resources.plugin_name;
@ -40,7 +42,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
{ {
Key = Top, Key = Top,
DisplayLabel = Resources.Top, DisplayLabel = Resources.Top,
Value = true, Value = false,
}, },
new PluginAdditionalOption() new PluginAdditionalOption()
{ {
@ -48,6 +50,12 @@ namespace Community.PowerToys.Run.Plugin.Everything
DisplayLabel = Resources.Wait, DisplayLabel = Resources.Wait,
Value = false, Value = false,
}, },
new PluginAdditionalOption()
{
Key = NoPreview,
DisplayLabel = Resources.NoPreview,
Value = false,
},
}; };
private IContextMenu _contextMenuLoader; private IContextMenu _contextMenuLoader;
@ -63,6 +71,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
} }
} }
private static CancellationTokenSource source;
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
_context = context; _context = context;
@ -91,9 +101,13 @@ namespace Community.PowerToys.Run.Plugin.Everything
if (!regexMatch.Success) if (!regexMatch.Success)
{ {
source?.Cancel();
source = new CancellationTokenSource();
CancellationToken token = source.Token;
source.CancelAfter(_wait ? 1000 : 75);
try try
{ {
results.AddRange(EverythingSearch(searchQuery, _wait, _top)); results.AddRange(EverythingSearch(searchQuery, _top, _noPreview, token));
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
@ -118,6 +132,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
} }
catch (Exception e) catch (Exception e)
{ {
source.Dispose();
Log.Exception("Everything Exception", e, GetType()); Log.Exception("Everything Exception", e, GetType());
} }
} }
@ -156,15 +171,18 @@ namespace Community.PowerToys.Run.Plugin.Everything
public void UpdateSettings(PowerLauncherPluginSettings settings) public void UpdateSettings(PowerLauncherPluginSettings settings)
{ {
var wait = false; var wait = false;
var top = true; var top = false;
var nopreview = false;
if (settings != null && settings.AdditionalOptions != null) if (settings != null && settings.AdditionalOptions != null)
{ {
wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false; wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false;
top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? true; top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? false;
nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false;
} }
_top = top; _top = top;
_wait = wait; _wait = wait;
_noPreview = nopreview;
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
@ -173,6 +191,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
{ {
if (disposing) if (disposing)
{ {
source.Dispose();
} }
disposed = true; disposed = true;

View File

@ -89,7 +89,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
public static extern void Everything_SetSort(Sort SortType); public static extern void Everything_SetSort(Sort SortType);
private const int max = 20; private const int max = 20;
private static CancellationTokenSource source;
#pragma warning disable SA1503 // Braces should not be omitted #pragma warning disable SA1503 // Braces should not be omitted
public static void EverythingSetup() public static void EverythingSetup()
{ {
@ -98,13 +97,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
Everything_SetMax(max); Everything_SetMax(max);
} }
public static IEnumerable<Result> EverythingSearch(string qry, bool wait, bool top) public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool noPreview, CancellationToken token)
{ {
source?.Cancel();
source = new CancellationTokenSource();
CancellationToken token = source.Token;
source.CancelAfter(wait ? 1000 : 75);
_ = Everything_SetSearchW(qry); _ = Everything_SetSearchW(qry);
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
if (!Everything_QueryW(true)) if (!Everything_QueryW(true))
@ -133,7 +127,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
Title = name, Title = name,
ToolTipData = new ToolTipData("Name : " + name, "Path : " + path), ToolTipData = new ToolTipData("Name : " + name, "Path : " + path),
SubTitle = Resources.plugin_name + ": " + fullPath, SubTitle = Resources.plugin_name + ": " + fullPath,
IcoPath = fullPath, IcoPath = noPreview ? "Images/Everything.ico.png" : fullPath,
ContextData = new SearchResult() ContextData = new SearchResult()
{ {
Path = fullPath, Path = fullPath,

View File

@ -114,6 +114,15 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Fast - Disable icon preview, fetching icons for non-local files may cause freezing..
/// </summary>
public static string NoPreview {
get {
return ResourceManager.GetString("NoPreview", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Open containing folder (Ctrl+Shift+E). /// Looks up a localized string similar to Open containing folder (Ctrl+Shift+E).
/// </summary> /// </summary>
@ -169,7 +178,7 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Insert result at the top of the list.. /// Looks up a localized string similar to Top - Insert result at the top of the list..
/// </summary> /// </summary>
public static string Top { public static string Top {
get { get {

View File

@ -135,6 +135,9 @@
<data name="folder_open_failed" xml:space="preserve"> <data name="folder_open_failed" xml:space="preserve">
<value>Fail to open folder at</value> <value>Fail to open folder at</value>
</data> </data>
<data name="NoPreview" xml:space="preserve">
<value>Fast - Disable icon preview, fetching icons for non-local files may cause freezing.</value>
</data>
<data name="open_containing_folder" xml:space="preserve"> <data name="open_containing_folder" xml:space="preserve">
<value>Open containing folder (Ctrl+Shift+E)</value> <value>Open containing folder (Ctrl+Shift+E)</value>
</data> </data>
@ -154,7 +157,7 @@
<value>Timed out before finishing the query</value> <value>Timed out before finishing the query</value>
</data> </data>
<data name="Top" xml:space="preserve"> <data name="Top" xml:space="preserve">
<value>Insert result at the top of the list.</value> <value>Top - Insert result at the top of the list.</value>
</data> </data>
<data name="Wait" xml:space="preserve"> <data name="Wait" xml:space="preserve">
<value>Wait - Wait longer for the query to finish.</value> <value>Wait - Wait longer for the query to finish.</value>

View File

@ -4,9 +4,9 @@
"IsGlobal": true, "IsGlobal": true,
"Name": "Everything", "Name": "Everything",
"Author": "Yu Chieh (Victor) Lin", "Author": "Yu Chieh (Victor) Lin",
"Version": "0.2.1", "Version": "0.2.5",
"Language": "csharp", "Language": "csharp",
"Website": "https://aka.ms/powertoys", "Website": "https://github.com/lin-ycv/EverythingPowerToys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll", "ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
"IcoPathDark": "Images\\Everything.dark.png", "IcoPathDark": "Images\\Everything.dark.png",
"IcoPathLight": "Images\\Everything.light.png" "IcoPathLight": "Images\\Everything.light.png"