Skip to content

Commit 01e749a

Browse files
committed
Fix an issue that store install/uninstall same plugin without restart shows error message error, should say already installed/uninstalled
1 parent 5b8b84a commit 01e749a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ public static bool PluginModified(string id)
542542

543543
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
544544
{
545-
InstallPlugin(newVersion, zipFilePath, checkModified:false);
545+
var success = InstallPlugin(newVersion, zipFilePath, checkModified:false);
546+
if (!success) return;
546547
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
547548
_modifiedPlugins.Add(existingVersion.ID);
548549
}
@@ -561,12 +562,13 @@ public static async Task UninstallPluginAsync(PluginMetadata plugin, bool remove
561562

562563
#region Internal functions
563564

564-
internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool checkModified)
565+
internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool checkModified)
565566
{
566567
if (checkModified && PluginModified(plugin.ID))
567568
{
568-
// Distinguish exception from installing same or less version
569-
throw new ArgumentException($"Plugin {plugin.Name} {plugin.ID} has been modified.", nameof(plugin));
569+
API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
570+
API.GetTranslation("pluginModifiedAlreadyMessage"));
571+
return false;
570572
}
571573

572574
// Unzip plugin files to temp folder
@@ -584,12 +586,16 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
584586

585587
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
586588
{
587-
throw new FileNotFoundException($"Unable to find plugin.json from the extracted zip file, or this path {pluginFolderPath} does not exist");
589+
API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
590+
string.Format(API.GetTranslation("fileNotFoundMessage"), pluginFolderPath));
591+
return false;
588592
}
589593

590594
if (SameOrLesserPluginVersionExists(metadataJsonFilePath))
591595
{
592-
throw new InvalidOperationException($"A plugin with the same ID and version already exists, or the version is greater than this downloaded plugin {plugin.Name}");
596+
API.ShowMsg(string.Format(API.GetTranslation("failedToInstallPluginTitle"), plugin.Name),
597+
API.GetTranslation("pluginExistAlreadyMessage"));
598+
return false;
593599
}
594600

595601
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
@@ -633,13 +639,17 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
633639
{
634640
_modifiedPlugins.Add(plugin.ID);
635641
}
642+
643+
return true;
636644
}
637645

638646
internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
639647
{
640648
if (checkModified && PluginModified(plugin.ID))
641649
{
642-
throw new ArgumentException($"Plugin {plugin.Name} has been modified");
650+
API.ShowMsg(string.Format(API.GetTranslation("failedToUninstallPluginTitle"), plugin.Name),
651+
API.GetTranslation("pluginModifiedAlreadyMessage"));
652+
return;
643653
}
644654

645655
if (removePluginSettings || removePluginFromSettings)

Flow.Launcher/Languages/en.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@
175175
<system:String x:Key="failedToRemovePluginSettingsMessage">Plugins: {0} - Fail to remove plugin settings files, please remove them manually</system:String>
176176
<system:String x:Key="failedToRemovePluginCacheTitle">Fail to remove plugin cache</system:String>
177177
<system:String x:Key="failedToRemovePluginCacheMessage">Plugins: {0} - Fail to remove plugin cache files, please remove them manually</system:String>
178+
<system:String x:Key="failedToInstallPluginTitle">Fail to install {0}</system:String>
179+
<system:String x:Key="failedToUninstallPluginTitle">Fail to uninstall {0}</system:String>
180+
<system:String x:Key="pluginModifiedAlreadyMessage">This plugin has been installed or uninstalled already, please restart Flow</system:String>
181+
<system:String x:Key="fileNotFoundMessage">Unable to find plugin.json from the extracted zip file, or this path {0} does not exist</system:String>
182+
<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>
178183

179184
<!-- Setting Plugin Store -->
180185
<system:String x:Key="pluginStore">Plugin Store</system:String>

0 commit comments

Comments
 (0)