From 55d1754ed6941835745baf7a64efac7be05a5cb1 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 16:05:33 +0800 Subject: [PATCH] Move PluginManifest public function to api --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 18 ++++++++++++++++++ Flow.Launcher/PublicAPIInstance.cs | 6 ++++++ .../SettingsPanePluginStoreViewModel.cs | 5 ++--- .../Main.cs | 3 +-- .../PluginsManager.cs | 12 +++++------- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index f178ebb90..513c2da84 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -344,5 +344,23 @@ namespace Flow.Launcher.Plugin /// Stop the loading bar in main window /// public void StopLoadingBar(); + + /// + /// Update the plugin manifest + /// + /// + /// FL has multiple urls to download the plugin manifest. Set this to true to only use the primary url. + /// + /// + /// + /// True if the manifest is updated successfully, false otherwise. + /// + public Task UpdatePluginManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default); + + /// + /// Get the plugin manifest + /// + /// + public IReadOnlyList GetUserPlugins(); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index d88eeb7c9..a8ec46982 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -28,6 +28,7 @@ using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.ViewModel; using JetBrains.Annotations; using Flow.Launcher.Core.Resource; +using Flow.Launcher.Core.ExternalPlugins; namespace Flow.Launcher { @@ -354,6 +355,11 @@ namespace Flow.Launcher public Task ShowProgressBoxAsync(string caption, Func, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress); + public Task UpdatePluginManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default) => + PluginsManifest.UpdateManifestAsync(usePrimaryUrlOnly, token); + + public IReadOnlyList GetUserPlugins() => PluginsManifest.UserPlugins; + #endregion #region Private Methods diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs index 15579a61d..23a316304 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Threading.Tasks; using CommunityToolkit.Mvvm.Input; -using Flow.Launcher.Core.ExternalPlugins; using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; @@ -14,7 +13,7 @@ public partial class SettingsPanePluginStoreViewModel : BaseModel public string FilterText { get; set; } = string.Empty; public IList ExternalPlugins => - PluginsManifest.UserPlugins?.Select(p => new PluginStoreItemViewModel(p)) + App.API.GetUserPlugins()?.Select(p => new PluginStoreItemViewModel(p)) .OrderByDescending(p => p.Category == PluginStoreItemViewModel.NewRelease) .ThenByDescending(p => p.Category == PluginStoreItemViewModel.RecentlyUpdated) .ThenByDescending(p => p.Category == PluginStoreItemViewModel.None) @@ -24,7 +23,7 @@ public partial class SettingsPanePluginStoreViewModel : BaseModel [RelayCommand] private async Task RefreshExternalPluginsAsync() { - if (await PluginsManifest.UpdateManifestAsync()) + if (await App.API.UpdatePluginManifestAsync()) { OnPropertyChanged(nameof(ExternalPlugins)); } diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs index b333aba42..742d85fc1 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Windows.Controls; using System.Threading.Tasks; using System.Threading; -using Flow.Launcher.Core.ExternalPlugins; using Flow.Launcher.Plugin.PluginsManager.ViewModels; using Flow.Launcher.Plugin.PluginsManager.Views; @@ -34,7 +33,7 @@ namespace Flow.Launcher.Plugin.PluginsManager contextMenu = new ContextMenu(Context); pluginManager = new PluginsManager(Context, Settings); - await PluginsManifest.UpdateManifestAsync(); + await Context.API.UpdatePluginManifestAsync(); } public List LoadContextMenus(Result selectedResult) diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index 9d2a8fe73..c742e457c 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -1,5 +1,4 @@ -using Flow.Launcher.Core.ExternalPlugins; -using Flow.Launcher.Core.Plugin; +using Flow.Launcher.Core.Plugin; using Flow.Launcher.Plugin.SharedCommands; using System; using System.Collections.Generic; @@ -236,7 +235,7 @@ namespace Flow.Launcher.Plugin.PluginsManager internal async ValueTask> RequestUpdateAsync(string search, CancellationToken token, bool usePrimaryUrlOnly = false) { - await PluginsManifest.UpdateManifestAsync(usePrimaryUrlOnly, token); + await Context.API.UpdatePluginManifestAsync(usePrimaryUrlOnly, token); var pluginFromLocalPath = null as UserPlugin; var updateFromLocalPath = false; @@ -249,7 +248,7 @@ namespace Flow.Launcher.Plugin.PluginsManager } var updateSource = !updateFromLocalPath - ? PluginsManifest.UserPlugins + ? Context.API.GetUserPlugins() : new List { pluginFromLocalPath }; var resultsForUpdate = ( @@ -601,7 +600,7 @@ namespace Flow.Launcher.Plugin.PluginsManager internal async ValueTask> RequestInstallOrUpdateAsync(string search, CancellationToken token, bool usePrimaryUrlOnly = false) { - await PluginsManifest.UpdateManifestAsync(usePrimaryUrlOnly, token); + await Context.API.UpdatePluginManifestAsync(usePrimaryUrlOnly, token); if (Uri.IsWellFormedUriString(search, UriKind.Absolute) && search.Split('.').Last() == ZipSuffix) @@ -611,8 +610,7 @@ namespace Flow.Launcher.Plugin.PluginsManager return InstallFromLocalPath(search); var results = - PluginsManifest - .UserPlugins + Context.API.GetUserPlugins() .Where(x => !PluginExists(x.ID) && !PluginManager.PluginModified(x.ID)) .Select(x => new Result