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
26 changes: 9 additions & 17 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@ public Task InitAsync(PluginInitContext context)
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;
}
Expand All @@ -69,15 +59,17 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)

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;
Expand Down
39 changes: 27 additions & 12 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,23 @@ internal PluginsManager(PluginInitContext context, Settings settings)
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()
Expand Down Expand Up @@ -151,8 +165,15 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
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",
Expand Down Expand Up @@ -276,20 +297,14 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
.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();

Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down