From 1ede69c4c172f52f69e1afc84335fb3a765b0580 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 30 Mar 2025 13:59:06 +0800 Subject: [PATCH] Make Plugin dictionary private --- Flow.Launcher.Core/Plugin/PluginManager.cs | 2 +- .../UserSettings/PluginSettings.cs | 17 ++++++++++++++++- .../ViewModels/SettingsPanePluginsViewModel.cs | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index eef4a0b71..4f869901c 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -622,7 +622,7 @@ namespace Flow.Launcher.Core.Plugin API.ShowMsg(API.GetTranslation("failedToRemovePluginCacheTitle"), string.Format(API.GetTranslation("failedToRemovePluginCacheMessage"), plugin.Name)); } - Settings.Plugins.Remove(plugin.ID); + Settings.RemovePluginSettings(plugin.ID); AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID); } diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index 6be347fe1..f7d4345c1 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -27,7 +27,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } - public Dictionary Plugins { get; set; } = new Dictionary(); + private Dictionary Plugins { get; set; } = new(); public void UpdatePluginSettings(List metadatas) { @@ -67,6 +67,21 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } } + + public Plugin GetPluginSettings(string id) + { + if (Plugins.TryGetValue(id, out var plugin)) + { + return plugin; + } + return null; + } + + public Plugin RemovePluginSettings(string id) + { + Plugins.Remove(id, out var plugin); + return plugin; + } } public class Plugin diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs index dd9e5786d..3c1aba400 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs @@ -30,8 +30,9 @@ public class SettingsPanePluginsViewModel : BaseModel .Select(plugin => new PluginViewModel { PluginPair = plugin, - PluginSettingsObject = _settings.PluginSettings.Plugins[plugin.Metadata.ID] + PluginSettingsObject = _settings.PluginSettings.GetPluginSettings(plugin.Metadata.ID) }) + .Where(plugin => plugin.PluginSettingsObject != null) .ToList(); public List FilteredPluginViewModels => PluginViewModels