From e8691c210dbd2ee79d9f06503402a8bd4a2e2720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 23 May 2021 12:28:45 +0800 Subject: [PATCH 01/25] No need for the wrapped Lazy instance in image loading. --- Flow.Launcher/ResultListBox.xaml | 2 +- Flow.Launcher/ViewModel/ResultViewModel.cs | 92 ++++++---------------- 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 2f9d06d814e..0f70dce4103 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -42,7 +42,7 @@ + Source="{Binding Image}" /> diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index c91bbb1074f..dd4b351c31e 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -11,62 +11,12 @@ namespace Flow.Launcher.ViewModel { public class ResultViewModel : BaseModel { - public class LazyAsync : Lazy> - { - private readonly T defaultValue; - - private readonly Action _updateCallback; - public new T Value - { - get - { - if (!IsValueCreated) - { - _ = Exercute(); // manually use callback strategy - - return defaultValue; - } - - if (!base.Value.IsCompletedSuccessfully) - return defaultValue; - - return base.Value.Result; - - // If none of the variables captured by the local function are captured by other lambdas, - // the compiler can avoid heap allocations. - async ValueTask Exercute() - { - await base.Value.ConfigureAwait(false); - _updateCallback(); - } - - } - } - public LazyAsync(Func> factory, T defaultValue, Action updateCallback) : base(factory) - { - if (defaultValue != null) - { - this.defaultValue = defaultValue; - } - - _updateCallback = updateCallback; - } - } - public ResultViewModel(Result result, Settings settings) { if (result != null) { Result = result; - - Image = new LazyAsync( - SetImage, - ImageLoader.DefaultImage, - () => - { - OnPropertyChanged(nameof(Image)); - }); - } + } Settings = settings; } @@ -85,44 +35,54 @@ public ResultViewModel(Result result, Settings settings) ? Result.SubTitle : Result.SubTitleToolTip; - public LazyAsync Image { get; set; } + private bool ImageLoaded; + + private ImageSource image = ImageLoader.DefaultImage; - private async ValueTask SetImage() + public ImageSource Image + { + get + { + if (!ImageLoaded) + { + ImageLoaded = true; + LoadImage(); + } + return image; + } + private set => image = value; + } + private async void LoadImage() { var imagePath = Result.IcoPath; if (string.IsNullOrEmpty(imagePath) && Result.Icon != null) { try { - return Result.Icon(); + Image = Result.Icon(); + return; } catch (Exception e) { Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e); - return ImageLoader.DefaultImage; } } if (ImageLoader.CacheContainImage(imagePath)) + { // will get here either when icoPath has value\icon delegate is null\when had exception in delegate - return ImageLoader.Load(imagePath); + Image = ImageLoader.Load(imagePath); + return; + } - return await Task.Run(() => ImageLoader.Load(imagePath)); + Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false); } public Result Result { get; } public override bool Equals(object obj) { - var r = obj as ResultViewModel; - if (r != null) - { - return Result.Equals(r.Result); - } - else - { - return false; - } + return obj is ResultViewModel r && Result.Equals(r.Result); } public override int GetHashCode() From 37f1a64495b848e5951cce83d57e375bb5fce5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 23 May 2021 22:54:52 +0800 Subject: [PATCH 02/25] avoid duplicate removing --- Flow.Launcher.Infrastructure/Image/ImageCache.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs index bb7ec681781..4e95278c10c 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs @@ -26,7 +26,7 @@ public class ImageCache private const int MaxCached = 50; public ConcurrentDictionary Data { get; private set; } = new ConcurrentDictionary(); private const int permissibleFactor = 2; - + public void Initialization(Dictionary usage) { foreach (var key in usage.Keys) @@ -35,6 +35,8 @@ public void Initialization(Dictionary usage) } } + private volatile bool removing; + public ImageSource this[string path] { get @@ -62,11 +64,13 @@ public ImageSource this[string path] // To prevent the dictionary from drastically increasing in size by caching images, the dictionary size is not allowed to grow more than the permissibleFactor * maxCached size // This is done so that we don't constantly perform this resizing operation and also maintain the image cache size at the same time - if (Data.Count > permissibleFactor * MaxCached) + if (Data.Count > permissibleFactor * MaxCached && !removing) { + removing = true; // To delete the images from the data dictionary based on the resizing of the Usage Dictionary. foreach (var key in Data.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key)) Data.TryRemove(key, out _); + removing = false; } } } From 1c6d207595c941c8bfa3d99a12d7e5c208ffe007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 24 May 2021 10:34:16 +0800 Subject: [PATCH 03/25] only modify property when async (avoid duplicate read) --- Flow.Launcher/ViewModel/ResultViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index dd4b351c31e..791aa6da98b 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -59,7 +59,7 @@ private async void LoadImage() { try { - Image = Result.Icon(); + image = Result.Icon(); return; } catch (Exception e) @@ -71,7 +71,7 @@ private async void LoadImage() if (ImageLoader.CacheContainImage(imagePath)) { // will get here either when icoPath has value\icon delegate is null\when had exception in delegate - Image = ImageLoader.Load(imagePath); + image = ImageLoader.Load(imagePath); return; } From 734a0cbfa1ac5fbfa47b4b6cdae13c8c20b2b051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 24 May 2021 10:35:18 +0800 Subject: [PATCH 04/25] Update comment --- Flow.Launcher/ViewModel/ResultViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 791aa6da98b..4d57f825296 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -75,6 +75,7 @@ private async void LoadImage() return; } + // We need to modify the property not field here to trigger the OnPropertyChanged event Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false); } From e6785dc9192b1c5de29eb46e89096343ac361c7f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 28 Jul 2021 21:24:16 +1000 Subject: [PATCH 05/25] standardise flow installer- remove version from exe installer --- Scripts/post_build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/post_build.ps1 b/Scripts/post_build.ps1 index b573b984b64..139880d2703 100644 --- a/Scripts/post_build.ps1 +++ b/Scripts/post_build.ps1 @@ -89,7 +89,7 @@ function Pack-Squirrel-Installer ($path, $version, $output) { Move-Item $temp\* $output -Force Remove-Item $temp - $file = "$output\Flow-Launcher-v$version.exe" + $file = "$output\Flow-Launcher-Setup.exe" Write-Host "Filename: $file" Move-Item "$output\Setup.exe" $file -Force @@ -109,7 +109,7 @@ function Publish-Self-Contained ($p) { function Publish-Portable ($outputLocation, $version) { - & $outputLocation\Flow-Launcher-v$v.exe --silent | Out-Null + & $outputLocation\Flow-Launcher-Setup.exe --silent | Out-Null mkdir "$env:LocalAppData\FlowLauncher\app-$version\UserData" Compress-Archive -Path $env:LocalAppData\FlowLauncher -DestinationPath $outputLocation\Flow-Launcher-Portable.zip } From 15d677f397084f3d7e86b5719418db569edb9954 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 28 Jul 2021 21:24:50 +1000 Subject: [PATCH 06/25] update readme to use standard exe installer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e89558d5705..7f5c2e33234 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Flow Launcher. Dedicated to make your workflow flow more seamlessly. Aimed at be ### Installation -| [Windows 7 and up installer](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest) | [Portable](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Portable.zip) | `WinGet install "Flow Launcher"` | +| [Windows 7 and up installer](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Setup.exe) | [Portable](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Portable.zip) | `WinGet install "Flow Launcher"` | | --------------------------------- | --------------------------------- | --------------------------------- | Windows may complain about security due to code not being signed, this will be completed at a later stage. If you downloaded from this repo, you are good to continue the set up. From a8d7dcdacbb85a241d7274cd7213d47fcb576abb Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 29 Jul 2021 07:58:17 +1000 Subject: [PATCH 07/25] remove extra space --- Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 995ac0fedfe..db081488062 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -185,7 +185,6 @@ internal async ValueTask> RequestUpdate(string search, Cancellation var uninstallSearch = search.Replace(Settings.HotkeyUpdate, string.Empty).TrimStart(); - var resultsForUpdate = from existingPlugin in Context.API.GetAllPlugins() join pluginFromManifest in pluginsManifest.UserPlugins From b023e8e5029fa08cf6dc22d0e17a0f4c4504e4b0 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 29 Jul 2021 18:01:56 +1000 Subject: [PATCH 08/25] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7f5c2e33234..9fda057c08d 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Flow Launcher. Dedicated to make your workflow flow more seamlessly. Aimed at be ### Installation -| [Windows 7 and up installer](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Setup.exe) | [Portable](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Portable.zip) | `WinGet install "Flow Launcher"` | +| [Windows 7+ installer](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Setup.exe) | [Portable](https://github.com/Flow-Launcher/Flow.Launcher/releases/latest/download/Flow-Launcher-Portable.zip) | `WinGet install "Flow Launcher"` | | --------------------------------- | --------------------------------- | --------------------------------- | Windows may complain about security due to code not being signed, this will be completed at a later stage. If you downloaded from this repo, you are good to continue the set up. @@ -59,10 +59,10 @@ Windows may complain about security due to code not being signed, this will be c - Open context menu: on the selected result, press Ctrl+O/Shift+Enter. - Cancel/Return to previous screen: Esc. - Install/Uninstall/Update plugins: in the search window, type `pm` `install`/`uninstall`/`update` + the plugin name. -- Saved user settings are located: +- Type `flow user data` to open your saved user settings folder. They are located at: - If using roaming: `%APPDATA%\FlowLauncher` - If using portable, by default: `%localappdata%\FlowLauncher\app-\UserData` -- Logs are saved along with your user settings folder. +- Type `open log location` to open your logs folder, they are saved along with your user settings folder. [More tips](https://flow-launcher.github.io/docs/#/usage-tips) @@ -74,7 +74,7 @@ If you are using Python plugins, flow will prompt to either select the location Vist [here](https://flow-launcher.github.io/docs/#/plugins) for our plugin portfolio. -If you are keen to write your own plugin for flow, please take a look at our plugin development documentation for [C#](https://flow-launcher.github.io/docs/#/develop-csharp-plugins) or [Python](https://flow-launcher.github.io/docs/#/develop-py-plugins) +If you are keen to write your own plugin for flow, please take a look at our plugin development documentation for [C#](https://flow-launcher.github.io/docs/#/develop-dotnet-plugins) or [Python](https://flow-launcher.github.io/docs/#/develop-py-plugins) ## Questions/Suggestions From 8d0459075ff71b769359de47974b937dd8d198ea Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 29 Jul 2021 18:08:18 +1000 Subject: [PATCH 09/25] fix formatting --- Flow.Launcher/ViewModel/MainViewModel.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index ca6ffe84573..6eee51bd883 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -108,9 +108,7 @@ async Task updateAction() } Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends"); - } - - ; + }; void continueAction(Task t) { From 8cfd80b96228c15b4760d907ededb510dc61b674 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 30 Jul 2021 12:30:21 +1000 Subject: [PATCH 10/25] delay the create query helper call to catch exception when Windows Search service is not running --- .../Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 6 +++--- .../Search/WindowsIndex/IndexSearch.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 9995f45d380..d367eddcab3 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -143,7 +143,7 @@ private async Task> WindowsIndexFileContentSearchAsync(Query query, return await IndexSearch.WindowsIndexSearchAsync( querySearchString, - queryConstructor.CreateQueryHelper(), + queryConstructor.CreateQueryHelper, queryConstructor.QueryForFileContentSearch, Settings.IndexSearchExcludedSubdirectoryPaths, query, @@ -181,7 +181,7 @@ private async Task> WindowsIndexFilesAndFoldersSearchAsync(Query qu return await IndexSearch.WindowsIndexSearchAsync( querySearchString, - queryConstructor.CreateQueryHelper(), + queryConstructor.CreateQueryHelper, queryConstructor.QueryForAllFilesAndFolders, Settings.IndexSearchExcludedSubdirectoryPaths, query, @@ -195,7 +195,7 @@ private async Task> WindowsIndexTopLevelFolderSearchAsync(Query que return await IndexSearch.WindowsIndexSearchAsync( path, - queryConstructor.CreateQueryHelper(), + queryConstructor.CreateQueryHelper, queryConstructor.QueryForTopLevelDirectorySearch, Settings.IndexSearchExcludedSubdirectoryPaths, query, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index 010a19b583a..2e90eadb6e4 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs @@ -88,7 +88,7 @@ internal static async Task> ExecuteWindowsIndexSearchAsync(string i internal async static Task> WindowsIndexSearchAsync( string searchString, - CSearchQueryHelper queryHelper, + Func createQueryHelper, Func constructQuery, List exclusionList, Query query, @@ -104,7 +104,7 @@ internal async static Task> WindowsIndexSearchAsync( var constructedQuery = constructQuery(searchString); return RemoveResultsInExclusionList( - await ExecuteWindowsIndexSearchAsync(constructedQuery, queryHelper.ConnectionString, query, token).ConfigureAwait(false), + await ExecuteWindowsIndexSearchAsync(constructedQuery, createQueryHelper().ConnectionString, query, token).ConfigureAwait(false), exclusionList, token); } From a29d4d181f022334b270e13c01b9363669a82367 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 30 Jul 2021 12:34:19 +1000 Subject: [PATCH 11/25] version bump Explorer --- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 59a31ec139c..9f27151880b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -9,7 +9,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.8.2", + "Version": "1.8.3", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From 9e21b2e831e0b7d6567d79939bcd475a7af6b30e Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 31 Jul 2021 13:59:27 +0800 Subject: [PATCH 12/25] include saving SearchPrecisionScore because it is not public before --- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index e7e7902d453..ebef2c6315a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -39,7 +39,8 @@ public string Language /// public bool ShouldUsePinyin { get; set; } = false; - internal SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular; + [JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))] + public SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular; [JsonIgnore] public string QuerySearchPrecisionString From 710d2a89a2f861b396eb91bef2b9d0f1a79557ac Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 31 Jul 2021 16:15:49 +0800 Subject: [PATCH 13/25] Use ValueTask as return value to suppress potential image error --- Flow.Launcher/ViewModel/ResultViewModel.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 4d57f825296..190f592d774 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -35,7 +35,7 @@ public ResultViewModel(Result result, Settings settings) ? Result.SubTitle : Result.SubTitleToolTip; - private bool ImageLoaded; + private volatile bool ImageLoaded; private ImageSource image = ImageLoader.DefaultImage; @@ -46,13 +46,13 @@ public ImageSource Image if (!ImageLoaded) { ImageLoaded = true; - LoadImage(); + _ = LoadImageAsync(); } return image; } private set => image = value; } - private async void LoadImage() + private async ValueTask LoadImageAsync() { var imagePath = Result.IcoPath; if (string.IsNullOrEmpty(imagePath) && Result.Icon != null) From a0835288e2335d03bd8aa985d1d63b55c3616dcb Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 31 Jul 2021 16:23:58 +0800 Subject: [PATCH 14/25] Use SemaphoreSlim to ensure cache only remove once --- .../Image/ImageCache.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs index 4e95278c10c..66104e80693 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows.Media; @@ -26,6 +27,7 @@ public class ImageCache private const int MaxCached = 50; public ConcurrentDictionary Data { get; private set; } = new ConcurrentDictionary(); private const int permissibleFactor = 2; + private SemaphoreSlim semaphore = new(1, 1); public void Initialization(Dictionary usage) { @@ -35,8 +37,6 @@ public void Initialization(Dictionary usage) } } - private volatile bool removing; - public ImageSource this[string path] { get @@ -62,15 +62,22 @@ public ImageSource this[string path] } ); - // To prevent the dictionary from drastically increasing in size by caching images, the dictionary size is not allowed to grow more than the permissibleFactor * maxCached size - // This is done so that we don't constantly perform this resizing operation and also maintain the image cache size at the same time - if (Data.Count > permissibleFactor * MaxCached && !removing) + SliceExtra(); + + async void SliceExtra() { - removing = true; - // To delete the images from the data dictionary based on the resizing of the Usage Dictionary. - foreach (var key in Data.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key)) - Data.TryRemove(key, out _); - removing = false; + // To prevent the dictionary from drastically increasing in size by caching images, the dictionary size is not allowed to grow more than the permissibleFactor * maxCached size + // This is done so that we don't constantly perform this resizing operation and also maintain the image cache size at the same time + if (Data.Count > permissibleFactor * MaxCached) + { + await semaphore.WaitAsync(); + // To delete the images from the data dictionary based on the resizing of the Usage Dictionary + // Double Check to avoid concurrent remove + if (Data.Count > permissibleFactor * MaxCached) + foreach (var key in Data.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key).ToArray()) + Data.TryRemove(key, out _); + semaphore.Release(); + } } } } From 7d1d41e6bafd0c46af6b23c3de0cad1cab4e0e84 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 2 Aug 2021 08:23:45 +1000 Subject: [PATCH 15/25] version bump --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 191ee480332..a764edbfd4b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: '1.8.1.{build}' +version: '1.8.2.{build}' init: - ps: | From df3b91ea9949aec1a40b0b73f8af9867f60a6e09 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 3 Aug 2021 07:58:35 +1000 Subject: [PATCH 16/25] fix PluginsManager's InstallOrUpdate focus --- .../Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs | 5 ++++- Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 995ac0fedfe..5d2e2bc5db8 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -120,7 +120,10 @@ internal async Task InstallOrUpdate(UserPlugin plugin) .ChangeQuery( $"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.HotkeyUpdate} {plugin.Name}"); - Application.Current.MainWindow.Show(); + var mainWindow = Application.Current.MainWindow; + mainWindow.Visibility = Visibility.Visible; + mainWindow.Focus(); + shouldHideWindow = false; return; diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json index fa916a29d03..08dab6fbf25 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json @@ -6,7 +6,7 @@ "Name": "Plugins Manager", "Description": "Management of installing, uninstalling or updating Flow Launcher plugins", "Author": "Jeremy Wu", - "Version": "1.8.4", + "Version": "1.8.5", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll", From 2a06cb989300a1334b5871ff004a45ebbe4ecf5a Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 4 Aug 2021 08:01:20 +1000 Subject: [PATCH 17/25] fix file path tool tip as file path instead --- Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index d0f78e14db8..dbc1faad9eb 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -144,7 +144,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score return true; }, TitleToolTip = Constants.ToolTipOpenContainingFolder, - SubTitleToolTip = Constants.ToolTipOpenContainingFolder, + SubTitleToolTip = filePath, ContextData = new SearchResult { Type = ResultType.File, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 9f27151880b..1881eff31c6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -9,7 +9,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.8.3", + "Version": "1.8.4", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From 7ada219c0c3fba3cf855f4ab9126058d50be0b5b Mon Sep 17 00:00:00 2001 From: pc223 <10551242+pc223@users.noreply.github.com> Date: Wed, 4 Aug 2021 22:12:11 +0700 Subject: [PATCH 18/25] Fix tool tip for folder --- Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index dbc1faad9eb..3130eebf798 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -52,7 +52,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string }, Score = score, TitleToolTip = Constants.ToolTipOpenDirectory, - SubTitleToolTip = Constants.ToolTipOpenDirectory, + SubTitleToolTip = subtitle, ContextData = new SearchResult { Type = ResultType.Folder, From 6a1bb17fb699e9bd53ab0020016f35c2978af4ab Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 5 Aug 2021 14:31:03 +0800 Subject: [PATCH 19/25] use < instead of != --- Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index abce8b41ea7..fd2464f2ee6 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -18,7 +18,7 @@ public void UpdatePluginSettings(List metadatas) // TODO: Remove. This is backwards compatibility for 1.8.0 release. // Introduced two new action keywords in Explorer, so need to update plugin setting in the UserData folder. - if (metadata.ID == "572be03c74c642baae319fc283e561a8" && metadata.ActionKeywords.Count != settings.ActionKeywords.Count) + if (metadata.ID == "572be03c74c642baae319fc283e561a8" && metadata.ActionKeywords.Count > settings.ActionKeywords.Count) { settings.ActionKeywords.Add(Query.GlobalPluginWildcardSign); // for index search settings.ActionKeywords.Add(Query.GlobalPluginWildcardSign); // for path search From 760333520c248493a25e37bff730bc8ce1a21ed8 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 6 Aug 2021 14:35:14 +0800 Subject: [PATCH 20/25] Adjust JsonRPCPlugin.cs Exception Handling --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 70 ++++++---------------- 1 file changed, 18 insertions(+), 52 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 22f547a5a75..d8dc2f42042 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -40,15 +40,7 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu public List LoadContextMenus(Result selectedResult) { var output = ExecuteContextMenu(selectedResult); - try - { - return DeserializedResult(output); - } - catch (Exception e) - { - Log.Exception($"|JsonRPCPlugin.LoadContextMenus|Exception on result <{selectedResult}>", e); - return null; - } + return DeserializedResult(output); } private static readonly JsonSerializerOptions options = new() @@ -65,23 +57,10 @@ private async Task> DeserializedResultAsync(Stream output) { if (output == Stream.Null) return null; - try - { - var queryResponseModel = - await JsonSerializer.DeserializeAsync(output, options); - - return ParseResults(queryResponseModel); - } - catch (JsonException e) - { - Log.Exception(GetType().FullName, "Unexpected Json Input", e); - } - finally - { - await output.DisposeAsync(); - } + var queryResponseModel = + await JsonSerializer.DeserializeAsync(output, options); - return null; + return ParseResults(queryResponseModel); } private List DeserializedResult(string output) @@ -249,12 +228,14 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati await using var source = process.StandardOutput.BaseStream; var buffer = BufferManager.GetStream(); - + token.Register(() => { // ReSharper disable once AccessToModifiedClosure // Manually Check whether disposed + // ReSharper disable once AccessToDisposedClosure if (!disposed && !process.HasExited) + // ReSharper disable once AccessToDisposedClosure process.Kill(); }); @@ -274,6 +255,14 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati token.ThrowIfCancellationRequested(); + if (buffer.Length == 0) + { + var errorMessage = process.StandardError.EndOfStream ? + "Empty JSONRPC Response" : + await process.StandardError.ReadToEndAsync(); + throw new InvalidDataException($"{context.CurrentPluginMetadata.Name}|{errorMessage}"); + } + if (!process.StandardError.EndOfStream) { using var standardError = process.StandardError; @@ -281,23 +270,12 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati if (!string.IsNullOrEmpty(error)) { - Log.Error($"|JsonRPCPlugin.ExecuteAsync|{error}"); - return Stream.Null; + Log.Error($"|{context.CurrentPluginMetadata.Name}.{nameof(ExecuteAsync)}|{error}"); } - - Log.Error("|JsonRPCPlugin.ExecuteAsync|Empty standard output and standard error."); - return Stream.Null; } return buffer; } - catch (Exception e) - { - Log.Exception( - $"|JsonRPCPlugin.ExecuteAsync|Exception for filename <{startInfo.FileName}> with argument <{startInfo.Arguments}>", - e); - return Stream.Null; - } finally { process?.Dispose(); @@ -307,20 +285,8 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati public async Task> QueryAsync(Query query, CancellationToken token) { - try - { - var output = await ExecuteQueryAsync(query, token); - return await DeserializedResultAsync(output); - } - catch (OperationCanceledException) - { - return null; - } - catch (Exception e) - { - Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e); - return null; - } + var output = await ExecuteQueryAsync(query, token); + return await DeserializedResultAsync(output); } public virtual Task InitAsync(PluginInitContext context) From 235fe4aacbebb9aa3f1a11e60364f99e415909b6 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sat, 7 Aug 2021 13:26:11 +1000 Subject: [PATCH 21/25] remove extra comments --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index d8dc2f42042..ae15d23a868 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -233,7 +233,6 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati { // ReSharper disable once AccessToModifiedClosure // Manually Check whether disposed - // ReSharper disable once AccessToDisposedClosure if (!disposed && !process.HasExited) // ReSharper disable once AccessToDisposedClosure process.Kill(); @@ -295,4 +294,4 @@ public virtual Task InitAsync(PluginInitContext context) return Task.CompletedTask; } } -} \ No newline at end of file +} From 77784492391221dc5544d72ba4fcb596c25c7ea5 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sat, 7 Aug 2021 13:26:38 +1000 Subject: [PATCH 22/25] remove extra comments --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index ae15d23a868..0df853a5d1f 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -234,7 +234,6 @@ protected async Task ExecuteAsync(ProcessStartInfo startInfo, Cancellati // ReSharper disable once AccessToModifiedClosure // Manually Check whether disposed if (!disposed && !process.HasExited) - // ReSharper disable once AccessToDisposedClosure process.Kill(); }); From 653dc83bd08819308e9a66bf3badeb9e4dc847e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Sun, 8 Aug 2021 13:45:18 +0800 Subject: [PATCH 23/25] fix error thrown in checking cache key when key is null --- Flow.Launcher.Infrastructure/Image/ImageCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs index 66104e80693..4d11abe2328 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs @@ -84,7 +84,7 @@ async void SliceExtra() public bool ContainsKey(string key) { - return Data.ContainsKey(key) && Data[key].imageSource != null; + return key is not null && Data.ContainsKey(key) && Data[key].imageSource != null; } public int CacheSize() From 3623e119d2be16c1c10668340978cb74de886732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Sun, 8 Aug 2021 13:46:31 +0800 Subject: [PATCH 24/25] add configureAwait(false) in SliceExtra ImageCache --- Flow.Launcher.Infrastructure/Image/ImageCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs index 4d11abe2328..13277c7d995 100644 --- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs +++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs @@ -70,7 +70,7 @@ async void SliceExtra() // This is done so that we don't constantly perform this resizing operation and also maintain the image cache size at the same time if (Data.Count > permissibleFactor * MaxCached) { - await semaphore.WaitAsync(); + await semaphore.WaitAsync().ConfigureAwait(false); // To delete the images from the data dictionary based on the resizing of the Usage Dictionary // Double Check to avoid concurrent remove if (Data.Count > permissibleFactor * MaxCached) From d536b6fd77aee1452837da78cb2c05dc8b86716d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 8 Aug 2021 18:47:39 +1000 Subject: [PATCH 25/25] change to path instead of subtitle parameter --- Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 3130eebf798..09315d9ddf6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -52,7 +52,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string }, Score = score, TitleToolTip = Constants.ToolTipOpenDirectory, - SubTitleToolTip = subtitle, + SubTitleToolTip = path, ContextData = new SearchResult { Type = ResultType.Folder,