Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

// Must use getter to avoid circular dependency
private Updater _updater;
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();

Check warning on line 52 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)

private readonly object _saveSettingsLock = new();

Expand Down Expand Up @@ -147,7 +147,7 @@
ShellCommand.Execute(startInfo);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]

Check warning on line 150 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)
public async void CopyToClipboard(string stringToCopy, bool directCopy = false, bool showDefaultNotification = true)
{
if (string.IsNullOrEmpty(stringToCopy))
Expand Down Expand Up @@ -251,7 +251,7 @@
Http.GetStreamAsync(url, token);

public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action<double> reportProgress = null,
CancellationToken token = default) =>Http.DownloadAsync(url, filePath, reportProgress, token);
CancellationToken token = default) => Http.DownloadAsync(url, filePath, reportProgress, token);

public void AddActionKeyword(string pluginId, string newActionKeyword) =>
PluginManager.AddActionKeyword(pluginId, newActionKeyword);
Expand Down
106 changes: 60 additions & 46 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
}
}

private async Task DownloadFileAsync(string prgBoxTitle, string downloadUrl, string filePath, CancellationTokenSource cts, bool deleteFile = true, bool showProgress = true)

Check warning on line 199 in Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`prg` is not a recognized word. (unrecognized-spelling)
{
if (deleteFile && File.Exists(filePath))
File.Delete(filePath);
Expand All @@ -204,7 +204,7 @@
if (showProgress)
{
var exceptionHappened = false;
await Context.API.ShowProgressBoxAsync(prgBoxTitle,

Check warning on line 207 in Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`prg` is not a recognized word. (unrecognized-spelling)
async (reportProgress) =>
{
if (reportProgress == null)
Expand Down Expand Up @@ -316,61 +316,75 @@
var downloadToFilePath = Path.Combine(Path.GetTempPath(),
$"{x.Name}-{x.NewVersion}.zip");

_ = Task.Run(async delegate
_ = Task.Run(async () =>
{
using var cts = new CancellationTokenSource();

if (!x.PluginNewUserPlugin.IsFromLocalInstallPath)
{
await DownloadFileAsync(
$"{Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")} {x.PluginNewUserPlugin.Name}",
x.PluginNewUserPlugin.UrlDownload, downloadToFilePath, cts);
}
else
try
{
downloadToFilePath = x.PluginNewUserPlugin.LocalInstallPath;
}
using var cts = new CancellationTokenSource();

// check if user cancelled download before installing plugin
if (cts.IsCancellationRequested)
{
return;
}
else
{
await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
downloadToFilePath);
if (!x.PluginNewUserPlugin.IsFromLocalInstallPath)
{
await DownloadFileAsync(
$"{Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin")} {x.PluginNewUserPlugin.Name}",
x.PluginNewUserPlugin.UrlDownload, downloadToFilePath, cts);
}
else
{
downloadToFilePath = x.PluginNewUserPlugin.LocalInstallPath;
}

if (Settings.AutoRestartAfterChanging)
// check if user cancelled download before installing plugin
if (cts.IsCancellationRequested)
{
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
string.Format(
Context.API.GetTranslation(
"plugin_pluginsmanager_update_success_restart"),
x.Name));
Context.API.RestartApp();
return;
}
else
{
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
string.Format(
Context.API.GetTranslation(
"plugin_pluginsmanager_update_success_no_restart"),
x.Name));
await Context.API.UpdatePluginAsync(x.PluginExistingMetadata, x.PluginNewUserPlugin,
downloadToFilePath);

if (Settings.AutoRestartAfterChanging)
{
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
string.Format(
Context.API.GetTranslation(
"plugin_pluginsmanager_update_success_restart"),
x.Name));
Context.API.RestartApp();
}
else
{
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
string.Format(
Context.API.GetTranslation(
"plugin_pluginsmanager_update_success_no_restart"),
x.Name));
}
}
}
}).ContinueWith(t =>
{
Context.API.LogException(ClassName, $"Update failed for {x.Name}",
t.Exception.InnerException);
Context.API.ShowMsg(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
x.Name));
}, token, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
catch (HttpRequestException e)
{
// show error message
Context.API.ShowMsgError(
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"), x.Name),
Context.API.GetTranslation("plugin_pluginsmanager_download_error"));
Context.API.LogException(ClassName, "An error occurred while downloading plugin", e);
return;
}
catch (Exception e)
{
// show error message
Context.API.LogException(ClassName, $"Update failed for {x.Name}", e);
Context.API.ShowMsgError(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
x.Name));
return;
}
});

return true;
},
Expand Down Expand Up @@ -436,7 +450,7 @@
catch (Exception ex)
{
Context.API.LogException(ClassName, $"Update failed for {plugin.Name}", ex.InnerException);
Context.API.ShowMsg(
Context.API.ShowMsgError(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
string.Format(
Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
Expand Down
Loading