Skip to content

Commit 07947c5

Browse files
committed
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
1 parent 71043be commit 07947c5

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
114114
return;
115115
}
116116

117+
if (Context.API.PluginModified(plugin.ID))
118+
{
119+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
120+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"),
121+
plugin.Name));
122+
return;
123+
}
124+
117125
string message;
118126
if (Settings.AutoRestartAfterChanging)
119127
{
@@ -158,7 +166,8 @@ await DownloadFileAsync(
158166
if (cts.IsCancellationRequested)
159167
return;
160168
else
161-
Install(plugin, filePath);
169+
if (!Install(plugin, filePath))
170+
return;
162171
}
163172
catch (HttpRequestException e)
164173
{
@@ -273,6 +282,7 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
273282
select
274283
new
275284
{
285+
existingPlugin.Metadata.ID,
276286
pluginUpdateSource.Name,
277287
pluginUpdateSource.Author,
278288
CurrentVersion = existingPlugin.Metadata.Version,
@@ -302,6 +312,14 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
302312
IcoPath = x.IcoPath,
303313
Action = e =>
304314
{
315+
if (Context.API.PluginModified(x.ID))
316+
{
317+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
318+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"),
319+
x.Name));
320+
return false;
321+
}
322+
305323
string message;
306324
if (Settings.AutoRestartAfterChanging)
307325
{
@@ -421,6 +439,14 @@ await DownloadFileAsync(
421439
IcoPath = icoPath,
422440
AsyncAction = async e =>
423441
{
442+
if (resultsForUpdate.All(x => Context.API.PluginModified(x.ID)))
443+
{
444+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
445+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"),
446+
string.Join(" ", resultsForUpdate.Select(x => x.Name))));
447+
return false;
448+
}
449+
424450
string message;
425451
if (Settings.AutoRestartAfterChanging)
426452
{
@@ -442,6 +468,7 @@ await DownloadFileAsync(
442468
return false;
443469
}
444470

471+
var anyPluginSuccess = false;
445472
await Task.WhenAll(resultsForUpdate.Select(async plugin =>
446473
{
447474
var downloadToFilePath = Path.Combine(Path.GetTempPath(),
@@ -462,6 +489,8 @@ await DownloadFileAsync(
462489
if (!await Context.API.UpdatePluginAsync(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin,
463490
downloadToFilePath))
464491
return;
492+
493+
anyPluginSuccess = true;
465494
}
466495
catch (Exception ex)
467496
{
@@ -474,6 +503,8 @@ await DownloadFileAsync(
474503
}
475504
}));
476505

506+
if (!anyPluginSuccess) return false;
507+
477508
if (Settings.AutoRestartAfterChanging)
478509
{
479510
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
@@ -682,7 +713,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdateAsync(string search
682713
return Search(results, search);
683714
}
684715

685-
private void Install(UserPlugin plugin, string downloadedFilePath)
716+
private bool Install(UserPlugin plugin, string downloadedFilePath)
686717
{
687718
if (!File.Exists(downloadedFilePath))
688719
throw new FileNotFoundException($"Plugin {plugin.ID} zip file not found at {downloadedFilePath}",
@@ -691,10 +722,12 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
691722
try
692723
{
693724
if (!Context.API.InstallPlugin(plugin, downloadedFilePath))
694-
return;
725+
return false;
695726

696727
if (!plugin.IsFromLocalInstallPath)
697728
File.Delete(downloadedFilePath);
729+
730+
return true;
698731
}
699732
catch (FileNotFoundException e)
700733
{
@@ -716,6 +749,8 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
716749
plugin.Name));
717750
Context.API.LogException(ClassName, e.Message, e);
718751
}
752+
753+
return false;
719754
}
720755

721756
internal List<Result> RequestUninstall(string search)
@@ -751,7 +786,10 @@ internal List<Result> RequestUninstall(string search)
751786
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
752787
{
753788
Context.API.HideMainWindow();
754-
await UninstallAsync(x.Metadata);
789+
if (!await UninstallAsync(x.Metadata))
790+
{
791+
return false;
792+
}
755793
if (Settings.AutoRestartAfterChanging)
756794
{
757795
Context.API.RestartApp();
@@ -776,24 +814,22 @@ internal List<Result> RequestUninstall(string search)
776814
return Search(results, search);
777815
}
778816

779-
private async Task UninstallAsync(PluginMetadata plugin)
817+
private async Task<bool> UninstallAsync(PluginMetadata plugin)
780818
{
781819
try
782820
{
783821
var removePluginSettings = Context.API.ShowMsgBox(
784822
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_subtitle"),
785823
Context.API.GetTranslation("plugin_pluginsmanager_keep_plugin_settings_title"),
786824
button: MessageBoxButton.YesNo) == MessageBoxResult.No;
787-
if (!await Context.API.UninstallPluginAsync(plugin, removePluginSettings))
788-
{
789-
return;
790-
}
825+
return await Context.API.UninstallPluginAsync(plugin, removePluginSettings);
791826
}
792827
catch (ArgumentException e)
793828
{
794829
Context.API.LogException(ClassName, e.Message, e);
795830
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_uninstall_error_title"),
796831
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_plugin_modified_error"), plugin.Name));
832+
return false;
797833
}
798834
}
799835
}

0 commit comments

Comments
 (0)