Optimize Logic

This commit is contained in:
弘韬 张 2021-02-03 10:23:38 +08:00
parent 2271ec16fd
commit 71664bddc0
2 changed files with 16 additions and 25 deletions

View file

@ -37,20 +37,10 @@ namespace Flow.Launcher.Plugin.PluginsManager
Settings = viewModel.Settings;
contextMenu = new ContextMenu(Context);
pluginManager = new PluginsManager(Context, Settings);
var updateManifestTask = pluginManager.UpdateManifest();
_ = updateManifestTask.ContinueWith(t =>
{
if (t.IsCompletedSuccessfully)
{
lastUpdateTime = DateTime.Now;
}
else
{
context.API.ShowMsg("Plugin Manifest Download Fail.",
"Please check if you can connect to github.com. " +
"This error means you may not be able to Install and Update Plugin.", pluginManager.icoPath, false);
}
});
_ = pluginManager.UpdateManifest().ContinueWith(_ =>
{
lastUpdateTime = DateTime.Now;
}, TaskContinuationOptions.OnlyOnRanToCompletion);
return Task.CompletedTask;
}

View file

@ -48,11 +48,18 @@ namespace Flow.Launcher.Plugin.PluginsManager
internal Task UpdateManifest()
{
return _downloadManifestTask = pluginsManifest.DownloadManifest().ContinueWith(t =>
if (_downloadManifestTask.Status == TaskStatus.Running)
{
return _downloadManifestTask;
}
else
{
return _downloadManifestTask = pluginsManifest.DownloadManifest().ContinueWith(t =>
Context.API.ShowMsg("Plugin Manifest Download Fail.",
"Please check if you can connect to github.com. " +
"This error means you may not be able to Install and Update Plugin.", icoPath, false),
TaskContinuationOptions.OnlyOnFaulted);
}
}
internal List<Result> GetDefaultHotKeys()
@ -155,14 +162,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
internal async ValueTask<List<Result>> RequestUpdate(string search, CancellationToken token)
{
if (!pluginsManifest.UserPlugins.Any() &&
_downloadManifestTask.Status != TaskStatus.Running)
if (!pluginsManifest.UserPlugins.Any())
{
_downloadManifestTask = pluginsManifest.DownloadManifest();
await UpdateManifest();
}
await _downloadManifestTask;
token.ThrowIfCancellationRequested();
@ -293,14 +297,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
{
if (!pluginsManifest.UserPlugins.Any() &&
_downloadManifestTask.Status != TaskStatus.Running)
if (!pluginsManifest.UserPlugins.Any())
{
_downloadManifestTask = pluginsManifest.DownloadManifest();
await UpdateManifest();
}
await _downloadManifestTask;
token.ThrowIfCancellationRequested();
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();