diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 81528b8d6..fdd4c7fed 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -57,7 +57,7 @@ namespace Flow.Launcher.Core.Plugin /// public static void Save() { - foreach (var pluginPair in GetAllPlugins()) + foreach (var pluginPair in GetAllInitializedPlugins()) { var savable = pluginPair.Plugin as ISavable; try @@ -76,7 +76,7 @@ namespace Flow.Launcher.Core.Plugin public static async ValueTask DisposePluginsAsync() { - foreach (var pluginPair in GetAllPlugins()) + foreach (var pluginPair in GetAllInitializedPlugins()) { await DisposePluginAsync(pluginPair); } @@ -104,7 +104,7 @@ namespace Flow.Launcher.Core.Plugin public static async Task ReloadDataAsync() { - await Task.WhenAll([.. GetAllPlugins().Select(plugin => plugin.Plugin switch + await Task.WhenAll([.. GetAllInitializedPlugins().Select(plugin => plugin.Plugin switch { IReloadable p => Task.Run(p.ReloadData), IAsyncReloadable p => p.ReloadDataAsync(), @@ -118,7 +118,7 @@ namespace Flow.Launcher.Core.Plugin public static async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true) { - await Task.WhenAll([.. GetAllPlugins().Select(plugin => plugin.Plugin switch + await Task.WhenAll([.. GetAllInitializedPlugins().Select(plugin => plugin.Plugin switch { IAsyncExternalPreview p => p.OpenPreviewAsync(path, sendFailToast), _ => Task.CompletedTask, @@ -127,7 +127,7 @@ namespace Flow.Launcher.Core.Plugin public static async Task CloseExternalPreviewAsync() { - await Task.WhenAll([.. GetAllPlugins().Select(plugin => plugin.Plugin switch + await Task.WhenAll([.. GetAllInitializedPlugins().Select(plugin => plugin.Plugin switch { IAsyncExternalPreview p => p.ClosePreviewAsync(), _ => Task.CompletedTask, @@ -136,7 +136,7 @@ namespace Flow.Launcher.Core.Plugin public static async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true) { - await Task.WhenAll([.. GetAllPlugins().Select(plugin => plugin.Plugin switch + await Task.WhenAll([.. GetAllInitializedPlugins().Select(plugin => plugin.Plugin switch { IAsyncExternalPreview p => p.SwitchPreviewAsync(path, sendFailToast), _ => Task.CompletedTask, @@ -512,14 +512,14 @@ namespace Flow.Launcher.Core.Plugin /// public static PluginPair GetPluginForId(string id) { - return GetAllPlugins().FirstOrDefault(o => o.Metadata.ID == id); + return GetAllInitializedPlugins().FirstOrDefault(o => o.Metadata.ID == id); } #endregion #region Get Plugin List - public static List GetAllPlugins() + public static List GetAllInitializedPlugins() { return [.. _allPlugins.Values]; } @@ -697,7 +697,7 @@ namespace Flow.Launcher.Core.Plugin if (!Version.TryParse(newMetadata.Version, out var newVersion)) return true; // If version is not valid, we assume it is lesser than any existing version - return GetAllPlugins().Any(x => x.Metadata.ID == newMetadata.ID + return GetAllInitializedPlugins().Any(x => x.Metadata.ID == newMetadata.ID && Version.TryParse(x.Metadata.Version, out var version) && newVersion <= version); } @@ -839,7 +839,7 @@ namespace Flow.Launcher.Core.Plugin // If we want to remove plugin from AllPlugins, // we need to dispose them so that they can release file handles // which can help FL to delete the plugin settings & cache folders successfully - var pluginPairs = GetAllPlugins().Where(p => p.Metadata.ID == plugin.ID).ToList(); + var pluginPairs = GetAllInitializedPlugins().Where(p => p.Metadata.ID == plugin.ID).ToList(); foreach (var pluginPair in pluginPairs) { await DisposePluginAsync(pluginPair); diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index cfa813d3f..4cefe4bc6 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -171,7 +171,7 @@ namespace Flow.Launcher.Plugin string GetTranslation(string key); /// - /// Get all loaded plugins + /// Get all initialized plugins /// /// List GetAllPlugins(); diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index dc64aefa9..bae953bbc 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -251,7 +251,7 @@ namespace Flow.Launcher public string GetTranslation(string key) => Internationalization.GetTranslation(key); - public List GetAllPlugins() => PluginManager.GetAllPlugins(); + public List GetAllPlugins() => PluginManager.GetAllInitializedPlugins(); public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs index 9e20d7a4a..8a84a7749 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs @@ -114,8 +114,9 @@ public partial class SettingsPanePluginsViewModel : BaseModel } } - private IList? _pluginViewModels; - public IList PluginViewModels => _pluginViewModels ??= PluginManager.GetAllPlugins() + private List? _pluginViewModels; + // Get all initialized plugins and ignore those that are not initialized + public List PluginViewModels => _pluginViewModels ??= App.API.GetAllPlugins() .OrderBy(plugin => plugin.Metadata.Disabled) .ThenBy(plugin => plugin.Metadata.Name) .Select(plugin => new PluginViewModel