Skip to content

Commit dcaa74d

Browse files
committed
Fix reduce nesting
Signed-off-by: Florian Grabmeier <[email protected]>
1 parent 24a6c68 commit dcaa74d

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

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

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -321,53 +321,54 @@ await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
321321

322322
if (MessageBox.Show(message,
323323
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
324-
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
324+
MessageBoxButton.YesNo) == MessageBoxResult.No)
325325
{
326-
Parallel.ForEach(resultsForUpdate, plugin =>
327-
{
328-
var downloadToFilePath = Path.Combine(Path.GetTempPath(), $"{plugin.Name}-{plugin.NewVersion}.zip");
326+
return false;
327+
}
329328

330-
_ = Task.Run(async delegate
331-
{
332-
if (File.Exists(downloadToFilePath))
333-
{
334-
File.Delete(downloadToFilePath);
335-
}
329+
Parallel.ForEach(resultsForUpdate, plugin =>
330+
{
331+
var downloadToFilePath = Path.Combine(Path.GetTempPath(), $"{plugin.Name}-{plugin.NewVersion}.zip");
336332

337-
await Http.DownloadAsync(plugin.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
338-
.ConfigureAwait(false);
333+
_ = Task.Run(async delegate
334+
{
335+
if (File.Exists(downloadToFilePath))
336+
{
337+
File.Delete(downloadToFilePath);
338+
}
339339

340-
PluginManager.UpdatePlugin(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, downloadToFilePath);
340+
await Http.DownloadAsync(plugin.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
341+
.ConfigureAwait(false);
341342

342-
}).ContinueWith(t =>
343-
{
344-
Log.Exception("PluginsManager", $"Update failed for {plugin.Name}",
345-
t.Exception.InnerException);
346-
Context.API.ShowMsg(
347-
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
348-
string.Format(
349-
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
350-
plugin.Name));
351-
}, TaskContinuationOptions.OnlyOnFaulted);
352-
});
343+
PluginManager.UpdatePlugin(plugin.PluginExistingMetadata, plugin.PluginNewUserPlugin, downloadToFilePath);
353344

354-
if (Settings.AutoRestartAfterChanging)
355-
{
356-
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
357-
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_all_success_restart"),
358-
resultsForUpdate.Count()));
359-
Context.API.RestartApp();
360-
}
361-
else
345+
}).ContinueWith(t =>
362346
{
363-
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
364-
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_all_success_no_restart"),
365-
resultsForUpdate.Count()));
366-
}
347+
Log.Exception("PluginsManager", $"Update failed for {plugin.Name}",
348+
t.Exception.InnerException);
349+
Context.API.ShowMsg(
350+
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
351+
string.Format(
352+
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
353+
plugin.Name));
354+
}, TaskContinuationOptions.OnlyOnFaulted);
355+
});
367356

368-
return true;
357+
if (Settings.AutoRestartAfterChanging)
358+
{
359+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
360+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_all_success_restart"),
361+
resultsForUpdate.Count()));
362+
Context.API.RestartApp();
369363
}
370-
return false;
364+
else
365+
{
366+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
367+
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_all_success_no_restart"),
368+
resultsForUpdate.Count()));
369+
}
370+
371+
return true;
371372
},
372373
ContextData = new UserPlugin()
373374
};

0 commit comments

Comments
 (0)