From 07947c5e1eb7c0e1ee064b4e3fac0a8a9ef91d2e Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 1 Jul 2025 12:34:48 +0800 Subject: [PATCH] Fix an issue that pm install/uninstall same plugin without restart says correct message but another message also pops up to say it's successfully installed. It should only one pop up notification to say that the plugin already installed/uninstalled --- .../PluginsManager.cs | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 3d3abba4a..3d74e26f2 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -114,6 +114,14 @@ namespace Flow.Launcher.Plugin.PluginsManager return; } + if (Context.API.PluginModified(plugin.ID)) + { + Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), + plugin.Name)); + return; + } + string message; if (Settings.AutoRestartAfterChanging) { @@ -158,7 +166,8 @@ namespace Flow.Launcher.Plugin.PluginsManager if (cts.IsCancellationRequested) return; else - Install(plugin, filePath); + if (!Install(plugin, filePath)) + return; } catch (HttpRequestException e) { @@ -273,6 +282,7 @@ namespace Flow.Launcher.Plugin.PluginsManager select new { + existingPlugin.Metadata.ID, pluginUpdateSource.Name, pluginUpdateSource.Author, CurrentVersion = existingPlugin.Metadata.Version, @@ -302,6 +312,14 @@ namespace Flow.Launcher.Plugin.PluginsManager IcoPath = x.IcoPath, Action = e => { + if (Context.API.PluginModified(x.ID)) + { + Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), + x.Name)); + return false; + } + string message; if (Settings.AutoRestartAfterChanging) { @@ -421,6 +439,14 @@ namespace Flow.Launcher.Plugin.PluginsManager IcoPath = icoPath, AsyncAction = async e => { + if (resultsForUpdate.All(x => Context.API.PluginModified(x.ID))) + { + Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"), + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), + string.Join(" ", resultsForUpdate.Select(x => x.Name)))); + return false; + } + string message; if (Settings.AutoRestartAfterChanging) { @@ -442,6 +468,7 @@ namespace Flow.Launcher.Plugin.PluginsManager return false; } + var anyPluginSuccess = false; await Task.WhenAll(resultsForUpdate.Select(async plugin => { var downloadToFilePath = Path.Combine(Path.GetTempPath(), @@ -462,6 +489,8 @@ namespace Flow.Launcher.Plugin.PluginsManager if (!await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, downloadToFilePath)) return; + + anyPluginSuccess = true; } catch (Exception ex) { @@ -474,6 +503,8 @@ namespace Flow.Launcher.Plugin.PluginsManager } })); + if (!anyPluginSuccess) return false; + if (Settings.AutoRestartAfterChanging) { Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"), @@ -682,7 +713,7 @@ namespace Flow.Launcher.Plugin.PluginsManager return Search(results, search); } - private void Install(UserPlugin plugin, string downloadedFilePath) + private bool Install(UserPlugin plugin, string downloadedFilePath) { if (!File.Exists(downloadedFilePath)) throw new FileNotFoundException($"Plugin {plugin.ID} zip file not found at {downloadedFilePath}", @@ -691,10 +722,12 @@ namespace Flow.Launcher.Plugin.PluginsManager try { if (!Context.API.InstallPlugin(plugin, downloadedFilePath)) - return; + return false; if (!plugin.IsFromLocalInstallPath) File.Delete(downloadedFilePath); + + return true; } catch (FileNotFoundException e) { @@ -716,6 +749,8 @@ namespace Flow.Launcher.Plugin.PluginsManager plugin.Name)); Context.API.LogException(ClassName, e.Message, e); } + + return false; } internal List RequestUninstall(string search) @@ -751,7 +786,10 @@ namespace Flow.Launcher.Plugin.PluginsManager MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Context.API.HideMainWindow(); - await UninstallAsync(x.Metadata); + if (!await UninstallAsync(x.Metadata)) + { + return false; + } if (Settings.AutoRestartAfterChanging) { Context.API.RestartApp(); @@ -776,7 +814,7 @@ namespace Flow.Launcher.Plugin.PluginsManager return Search(results, search); } - private async Task UninstallAsync(PluginMetadata plugin) + private async Task UninstallAsync(PluginMetadata plugin) { try { @@ -784,16 +822,14 @@ namespace Flow.Launcher.Plugin.PluginsManager Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"), Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"), button: MessageBoxButton.YesNo) == MessageBoxResult.No; - if (!await Context.API.UninstallPluginAsync(plugin, removePluginSettings)) - { - return; - } + return await Context.API.UninstallPluginAsync(plugin, removePluginSettings); } catch (ArgumentException e) { Context.API.LogException(ClassName, e.Message, e); Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_error_title"), string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), plugin.Name)); + return false; } } }