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

This commit is contained in:
Jack251970 2025-07-01 12:34:48 +08:00
parent 71043be078
commit 07947c5e1e

View file

@ -114,6 +114,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
return; 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; string message;
if (Settings.AutoRestartAfterChanging) if (Settings.AutoRestartAfterChanging)
{ {
@ -158,7 +166,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (cts.IsCancellationRequested) if (cts.IsCancellationRequested)
return; return;
else else
Install(plugin, filePath); if (!Install(plugin, filePath))
return;
} }
catch (HttpRequestException e) catch (HttpRequestException e)
{ {
@ -273,6 +282,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
select select
new new
{ {
existingPlugin.Metadata.ID,
pluginUpdateSource.Name, pluginUpdateSource.Name,
pluginUpdateSource.Author, pluginUpdateSource.Author,
CurrentVersion = existingPlugin.Metadata.Version, CurrentVersion = existingPlugin.Metadata.Version,
@ -302,6 +312,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
IcoPath = x.IcoPath, IcoPath = x.IcoPath,
Action = e => 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; string message;
if (Settings.AutoRestartAfterChanging) if (Settings.AutoRestartAfterChanging)
{ {
@ -421,6 +439,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
IcoPath = icoPath, IcoPath = icoPath,
AsyncAction = async e => 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; string message;
if (Settings.AutoRestartAfterChanging) if (Settings.AutoRestartAfterChanging)
{ {
@ -442,6 +468,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
return false; return false;
} }
var anyPluginSuccess = false;
await Task.WhenAll(resultsForUpdate.Select(async plugin => await Task.WhenAll(resultsForUpdate.Select(async plugin =>
{ {
var downloadToFilePath = Path.Combine(Path.GetTempPath(), var downloadToFilePath = Path.Combine(Path.GetTempPath(),
@ -462,6 +489,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (!await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, if (!await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
downloadToFilePath)) downloadToFilePath))
return; return;
anyPluginSuccess = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -474,6 +503,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
} }
})); }));
if (!anyPluginSuccess) return false;
if (Settings.AutoRestartAfterChanging) if (Settings.AutoRestartAfterChanging)
{ {
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"), Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
@ -682,7 +713,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
return Search(results, search); return Search(results, search);
} }
private void Install(UserPlugin plugin, string downloadedFilePath) private bool Install(UserPlugin plugin, string downloadedFilePath)
{ {
if (!File.Exists(downloadedFilePath)) if (!File.Exists(downloadedFilePath))
throw new FileNotFoundException($"Plugin {plugin.ID} zip file not found at {downloadedFilePath}", throw new FileNotFoundException($"Plugin {plugin.ID} zip file not found at {downloadedFilePath}",
@ -691,10 +722,12 @@ namespace Flow.Launcher.Plugin.PluginsManager
try try
{ {
if (!Context.API.InstallPlugin(plugin, downloadedFilePath)) if (!Context.API.InstallPlugin(plugin, downloadedFilePath))
return; return false;
if (!plugin.IsFromLocalInstallPath) if (!plugin.IsFromLocalInstallPath)
File.Delete(downloadedFilePath); File.Delete(downloadedFilePath);
return true;
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
@ -716,6 +749,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
plugin.Name)); plugin.Name));
Context.API.LogException(ClassName, e.Message, e); Context.API.LogException(ClassName, e.Message, e);
} }
return false;
} }
internal List<Result> RequestUninstall(string search) internal List<Result> RequestUninstall(string search)
@ -751,7 +786,10 @@ namespace Flow.Launcher.Plugin.PluginsManager
MessageBoxButton.YesNo) == MessageBoxResult.Yes) MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
Context.API.HideMainWindow(); Context.API.HideMainWindow();
await UninstallAsync(x.Metadata); if (!await UninstallAsync(x.Metadata))
{
return false;
}
if (Settings.AutoRestartAfterChanging) if (Settings.AutoRestartAfterChanging)
{ {
Context.API.RestartApp(); Context.API.RestartApp();
@ -776,7 +814,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
return Search(results, search); return Search(results, search);
} }
private async Task UninstallAsync(PluginMetadata plugin) private async Task<bool> UninstallAsync(PluginMetadata plugin)
{ {
try 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_subtitle"),
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"), Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
button: MessageBoxButton.YesNo) == MessageBoxResult.No; button: MessageBoxButton.YesNo) == MessageBoxResult.No;
if (!await Context.API.UninstallPluginAsync(plugin, removePluginSettings)) return await Context.API.UninstallPluginAsync(plugin, removePluginSettings);
{
return;
}
} }
catch (ArgumentException e) catch (ArgumentException e)
{ {
Context.API.LogException(ClassName, e.Message, e); Context.API.LogException(ClassName, e.Message, e);
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_error_title"), Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_error_title"),
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), plugin.Name)); string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), plugin.Name));
return false;
} }
} }
} }