From 8aebf958aa940770c23854167d4c0304a7890fd3 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Thu, 9 Jan 2025 12:13:46 +0800
Subject: [PATCH] Check ui thread when calling close function & Update
documents
---
Flow.Launcher.Core/ProgressBoxEx.xaml.cs | 7 ++++++-
Flow.Launcher.Plugin/IProgressBoxEx.cs | 4 ++--
.../PluginsManager.cs | 14 +++-----------
3 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/Flow.Launcher.Core/ProgressBoxEx.xaml.cs b/Flow.Launcher.Core/ProgressBoxEx.xaml.cs
index 9a32f7303..f5d34617b 100644
--- a/Flow.Launcher.Core/ProgressBoxEx.xaml.cs
+++ b/Flow.Launcher.Core/ProgressBoxEx.xaml.cs
@@ -66,11 +66,16 @@ namespace Flow.Launcher.Core
private new void Close()
{
+ if (!Application.Current.Dispatcher.CheckAccess())
+ {
+ Application.Current.Dispatcher.Invoke(Close);
+ }
+
if (_isClosed)
{
return;
}
-
+
base.Close();
_isClosed = true;
}
diff --git a/Flow.Launcher.Plugin/IProgressBoxEx.cs b/Flow.Launcher.Plugin/IProgressBoxEx.cs
index 6468e3c83..27b061895 100644
--- a/Flow.Launcher.Plugin/IProgressBoxEx.cs
+++ b/Flow.Launcher.Plugin/IProgressBoxEx.cs
@@ -6,7 +6,7 @@
public interface IProgressBoxEx
{
///
- /// Show progress box. It should be called from the main ui thread.
+ /// Show progress box.
///
///
/// Progress value. Should be between 0 and 100. When progress is 100, the progress box will be closed.
@@ -14,7 +14,7 @@ public interface IProgressBoxEx
public void ReportProgress(double progress);
///
- /// Close progress box. It should be called from the main ui thread.
+ /// Close progress box.
///
public void Close();
}
diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
index 2923f7eef..0af2af5ec 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
- CleanupProgressBoxEx(prgBox);
+ prgBox?.Close();
}
else
{
@@ -217,7 +217,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (HttpRequestException e)
{
// force close progress box
- CleanupProgressBoxEx(prgBox);
+ prgBox?.Close();
// show error message
Context.API.ShowMsgError(
@@ -230,7 +230,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (Exception e)
{
// force close progress box
- CleanupProgressBoxEx(prgBox);
+ prgBox?.Close();
// show error message
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
@@ -256,14 +256,6 @@ namespace Flow.Launcher.Plugin.PluginsManager
}
}
- private static void CleanupProgressBoxEx(IProgressBoxEx prgBox)
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- prgBox?.Close();
- });
- }
-
internal async ValueTask> RequestUpdateAsync(string search, CancellationToken token,
bool usePrimaryUrlOnly = false)
{