mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #314 from taooceros/FixUnexpectedErrorNotice
Optimize manifest downloading behavior
This commit is contained in:
commit
55b0a91cdc
3 changed files with 37 additions and 30 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -69,15 +59,17 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
if ((DateTime.Now - lastUpdateTime).TotalHours > 12) // 12 hours
|
||||
{
|
||||
await pluginManager.UpdateManifest();
|
||||
lastUpdateTime = DateTime.Now;
|
||||
_ = pluginManager.UpdateManifest().ContinueWith(t =>
|
||||
{
|
||||
lastUpdateTime = DateTime.Now;
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
|
||||
return search switch
|
||||
{
|
||||
var s when s.StartsWith(Settings.HotKeyInstall) => await pluginManager.RequestInstallOrUpdate(s, token),
|
||||
var s when s.StartsWith(Settings.HotkeyUninstall) => pluginManager.RequestUninstall(s),
|
||||
var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
|
||||
var s when s.StartsWith(Settings.HotkeyUpdate) => await pluginManager.RequestUpdate(s, token),
|
||||
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
|
||||
{
|
||||
hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;
|
||||
|
|
|
|||
|
|
@ -48,9 +48,23 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
Settings = settings;
|
||||
}
|
||||
|
||||
internal async Task UpdateManifest()
|
||||
private Task _downloadManifestTask = Task.CompletedTask;
|
||||
|
||||
|
||||
internal Task UpdateManifest()
|
||||
{
|
||||
await pluginsManifest.DownloadManifest();
|
||||
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()
|
||||
|
|
@ -151,8 +165,15 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
Context.API.RestartApp();
|
||||
}
|
||||
|
||||
internal List<Result> RequestUpdate(string search)
|
||||
internal async ValueTask<List<Result>> RequestUpdate(string search, CancellationToken token)
|
||||
{
|
||||
if (!pluginsManifest.UserPlugins.Any())
|
||||
{
|
||||
await UpdateManifest();
|
||||
}
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
var autocompletedResults = AutoCompleteReturnAllResults(search,
|
||||
Settings.HotkeyUpdate,
|
||||
"Update",
|
||||
|
|
@ -276,20 +297,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
.ToList();
|
||||
}
|
||||
|
||||
private Task _downloadManifestTask = Task.CompletedTask;
|
||||
|
||||
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;
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return null;
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty).Trim();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"Name": "Plugins Manager",
|
||||
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
|
||||
"Author": "Jeremy Wu",
|
||||
"Version": "1.6.4",
|
||||
"Version": "1.7.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",
|
||||
|
|
|
|||
Loading…
Reference in a new issue