Fix an issue that store install/uninstall same plugin without restart shows error message error, should say already installed/uninstalled

This commit is contained in:
Jack251970 2025-06-30 13:07:19 +08:00
parent 5b8b84a34c
commit 01e749ac88
2 changed files with 22 additions and 7 deletions

View file

@ -542,7 +542,8 @@ namespace Flow.Launcher.Core.Plugin
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath) public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
{ {
InstallPlugin(newVersion, zipFilePath, checkModified:false); var success = InstallPlugin(newVersion, zipFilePath, checkModified:false);
if (!success) return;
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false); await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
_modifiedPlugins.Add(existingVersion.ID); _modifiedPlugins.Add(existingVersion.ID);
} }
@ -561,12 +562,13 @@ namespace Flow.Launcher.Core.Plugin
#region Internal functions #region Internal functions
internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool checkModified) internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool checkModified)
{ {
if (checkModified && PluginModified(plugin.ID)) if (checkModified && PluginModified(plugin.ID))
{ {
// Distinguish exception from installing same or less version API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
throw new ArgumentException($"Plugin {plugin.Name} {plugin.ID} has been modified.", nameof(plugin)); API.GetTranslation("pluginModifiedAlreadyMessage"));
return false;
} }
// Unzip plugin files to temp folder // Unzip plugin files to temp folder
@ -584,12 +586,16 @@ namespace Flow.Launcher.Core.Plugin
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath)) if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
{ {
throw new FileNotFoundException($"Unable to find plugin.json from the extracted zip file, or this path {pluginFolderPath} does not exist"); API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
string.Format(API.GetTranslation("fileNotFoundMessage"), pluginFolderPath));
return false;
} }
if (SameOrLesserPluginVersionExists(metadataJsonFilePath)) if (SameOrLesserPluginVersionExists(metadataJsonFilePath))
{ {
throw new InvalidOperationException($"A plugin with the same ID and version already exists, or the version is greater than this downloaded plugin {plugin.Name}"); API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
API.GetTranslation("pluginExistAlreadyMessage"));
return false;
} }
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}"; var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
@ -633,13 +639,17 @@ namespace Flow.Launcher.Core.Plugin
{ {
_modifiedPlugins.Add(plugin.ID); _modifiedPlugins.Add(plugin.ID);
} }
return true;
} }
internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified) internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
{ {
if (checkModified && PluginModified(plugin.ID)) if (checkModified && PluginModified(plugin.ID))
{ {
throw new ArgumentException($"Plugin {plugin.Name} has been modified"); API.ShowMsg(string.Format(API.GetTranslation("failedToUninstallPluginTitle"), plugin.Name),
API.GetTranslation("pluginModifiedAlreadyMessage"));
return;
} }
if (removePluginSettings || removePluginFromSettings) if (removePluginSettings || removePluginFromSettings)

View file

@ -175,6 +175,11 @@
<system:String x:Key="failedToRemovePluginSettingsMessage">Plugins: {0} - Fail to remove plugin settings files, please remove them manually</system:String> <system:String x:Key="failedToRemovePluginSettingsMessage">Plugins: {0} - Fail to remove plugin settings files, please remove them manually</system:String>
<system:String x:Key="failedToRemovePluginCacheTitle">Fail to remove plugin cache</system:String> <system:String x:Key="failedToRemovePluginCacheTitle">Fail to remove plugin cache</system:String>
<system:String x:Key="failedToRemovePluginCacheMessage">Plugins: {0} - Fail to remove plugin cache files, please remove them manually</system:String> <system:String x:Key="failedToRemovePluginCacheMessage">Plugins: {0} - Fail to remove plugin cache files, please remove them manually</system:String>
<system:String x:Key="failedToInstallPluginTitle">Fail to install {0}</system:String>
<system:String x:Key="failedToUninstallPluginTitle">Fail to uninstall {0}</system:String>
<system:String x:Key="pluginModifiedAlreadyMessage">This plugin has been installed or uninstalled already, please restart Flow</system:String>
<system:String x:Key="fileNotFoundMessage">Unable to find plugin.json from the extracted zip file, or this path {0} does not exist</system:String>
<system:String x:Key="pluginExistAlreadyMessage">A plugin with the same ID and version already exists, or the version is greater than this downloaded plugin</system:String>
<!-- Setting Plugin Store --> <!-- Setting Plugin Store -->
<system:String x:Key="pluginStore">Plugin Store</system:String> <system:String x:Key="pluginStore">Plugin Store</system:String>