From 122887e6a61f629a4574fe1ebfa62b7a115e9b2f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 9 Jan 2025 16:37:52 +0800 Subject: [PATCH] Await close event from non-ui thread --- Flow.Launcher.Core/ProgressBoxEx.xaml.cs | 10 ++++++++-- Flow.Launcher.Plugin/IProgressBoxEx.cs | 6 ++++-- .../PluginsManager.cs | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/ProgressBoxEx.xaml.cs b/Flow.Launcher.Core/ProgressBoxEx.xaml.cs index f5d34617b..00f4a8050 100644 --- a/Flow.Launcher.Core/ProgressBoxEx.xaml.cs +++ b/Flow.Launcher.Core/ProgressBoxEx.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using Flow.Launcher.Infrastructure.Logger; @@ -64,13 +65,18 @@ namespace Flow.Launcher.Core } } - private new void Close() + public async Task CloseAsync() { if (!Application.Current.Dispatcher.CheckAccess()) { - Application.Current.Dispatcher.Invoke(Close); + await Application.Current.Dispatcher.InvokeAsync(Close); } + Close(); + } + + private new void Close() + { if (_isClosed) { return; diff --git a/Flow.Launcher.Plugin/IProgressBoxEx.cs b/Flow.Launcher.Plugin/IProgressBoxEx.cs index 27b061895..50ee6eb55 100644 --- a/Flow.Launcher.Plugin/IProgressBoxEx.cs +++ b/Flow.Launcher.Plugin/IProgressBoxEx.cs @@ -1,4 +1,6 @@ -namespace Flow.Launcher.Plugin; +using System.Threading.Tasks; + +namespace Flow.Launcher.Plugin; /// /// Interface for progress box @@ -16,5 +18,5 @@ public interface IProgressBoxEx /// /// Close progress box. /// - public void Close(); + public Task CloseAsync(); } diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 0af2af5ec..f5399d53d 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -196,7 +196,7 @@ namespace Flow.Launcher.Plugin.PluginsManager if (downloadCancelled) return; else - prgBox?.Close(); + await prgBox?.CloseAsync(); } else { @@ -217,7 +217,7 @@ namespace Flow.Launcher.Plugin.PluginsManager catch (HttpRequestException e) { // force close progress box - prgBox?.Close(); + await prgBox?.CloseAsync(); // show error message Context.API.ShowMsgError( @@ -230,7 +230,7 @@ namespace Flow.Launcher.Plugin.PluginsManager catch (Exception e) { // force close progress box - prgBox?.Close(); + await prgBox?.CloseAsync(); // show error message Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),