From 3d064046141a11f0b6f89a1985b7cf831761db2a Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sun, 10 Oct 2021 16:46:54 -0500 Subject: [PATCH] Move PluginsManifest to Flow.Launcher.Core & Change PluginStore Binding to PluginsManifest --- .../ExternalPlugins/PluginsManifest.cs | 57 ++++++++++++++++ .../ExternalPlugins}/UserPlugin.cs | 6 +- Flow.Launcher/SettingWindow.xaml | 68 +++++++++---------- .../ViewModel/SettingWindowViewModel.cs | 9 +++ .../ContextMenu.cs | 4 +- .../Main.cs | 6 +- .../Models/PluginsManifest.cs | 31 --------- .../PluginsManager.cs | 21 +++--- 8 files changed, 117 insertions(+), 85 deletions(-) create mode 100644 Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs rename {Plugins/Flow.Launcher.Plugin.PluginsManager/Models => Flow.Launcher.Core/ExternalPlugins}/UserPlugin.cs (77%) delete mode 100644 Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs diff --git a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs new file mode 100644 index 000000000..c0cd022ea --- /dev/null +++ b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs @@ -0,0 +1,57 @@ +using Flow.Launcher.Infrastructure.Http; +using Flow.Launcher.Infrastructure.Logger; +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Flow.Launcher.Core.ExternalPlugins +{ + public static class PluginsManifest + { + static PluginsManifest() + { + UpdateTask = UpdateManifestAsync(); + } + + public static List UserPlugins { get; private set; } = new List(); + + public static Task UpdateTask { get; private set; } + + private static readonly SemaphoreSlim manifestUpdateLock = new(1); + + public static Task UpdateManifestAsync() + { + if (manifestUpdateLock.CurrentCount == 0) + { + return UpdateTask; + } + + return UpdateTask = DownloadManifestAsync(); + } + + private async static Task DownloadManifestAsync() + { + try + { + await manifestUpdateLock.WaitAsync().ConfigureAwait(false); + + await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json") + .ConfigureAwait(false); + + UserPlugins = await JsonSerializer.DeserializeAsync>(jsonStream).ConfigureAwait(false); + } + catch (Exception e) + { + Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e); + + UserPlugins = new List(); + } + finally + { + manifestUpdateLock.Release(); + } + } + } +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/UserPlugin.cs b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs similarity index 77% rename from Plugins/Flow.Launcher.Plugin.PluginsManager/Models/UserPlugin.cs rename to Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs index c1af3014b..f98815c1a 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/UserPlugin.cs +++ b/Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs @@ -1,7 +1,6 @@ - -namespace Flow.Launcher.Plugin.PluginsManager.Models +namespace Flow.Launcher.Core.ExternalPlugins { - public class UserPlugin + public record UserPlugin { public string ID { get; set; } public string Name { get; set; } @@ -12,5 +11,6 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models public string Website { get; set; } public string UrlDownload { get; set; } public string UrlSourceCode { get; set; } + public string IcoPath { get; set; } } } diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index c02c487a6..b091f5ef2 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -657,28 +657,28 @@ ToolTip="Change Plugin Results Priority" Margin="5 0 0 0" Cursor="Hand" Click="OnPluginPriorityClick"> - + - - - - + + + + - -