From d84eff77129892ec129f8c0520e9a36511970012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Thu, 13 May 2021 19:29:21 +0800 Subject: [PATCH] Remove unneccessary api, rename storage api, and update comment --- Flow.Launcher.Plugin/IPublicAPI.cs | 20 +++++-------------- Flow.Launcher/PublicAPIInstance.cs | 4 ++-- .../Main.cs | 2 +- .../Flow.Launcher.Plugin.Calculator/Main.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/Main.cs | 2 +- .../ViewModels/SettingsViewModel.cs | 2 +- .../Main.cs | 2 +- Plugins/Flow.Launcher.Plugin.Program/Main.cs | 2 +- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 2 +- Plugins/Flow.Launcher.Plugin.Url/Main.cs | 2 +- .../Flow.Launcher.Plugin.WebSearch/Main.cs | 2 +- 11 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 368dfe7b1..bdd3e70a2 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -165,30 +165,20 @@ namespace Flow.Launcher.Plugin void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = ""); /// - /// Load JsonStorage for current plugin. This is the method used to load settings from json in Flow. + /// Load JsonStorage for current plugin's setting. This is the method used to load settings from json in Flow. /// When the file is not exist, it will create a new instance for the specific type. /// /// Type for deserialization /// - T LoadJsonStorage() where T : new(); + T LoadSettingJsonStorage() where T : new(); /// - /// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow.Launcher + /// Save JsonStorage for current plugin's setting. This is the method used to save settings to json in Flow.Launcher /// This method will save the original instance loaded with LoadJsonStorage. + /// This API call is for manually Save. Flow will automatically save all setting that has registered. /// /// Type for Serialization /// - void SaveJsonStorage() where T : new(); - - /// - /// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow.Launcher - /// This method will override the original class instance loaded from LoadJsonStorage - /// This method allows registering a type with provided instance so that it won't create a new one. - /// Only use it when you would like to create a new instance of the type instance and overwrite the original one - /// stored before. - /// - /// Type for Serialization - /// - void SaveJsonStorage(T settings) where T : new(); + void SaveSettingJsonStorage() where T : new(); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 3ddaec4d4..058506e3a 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -145,7 +145,7 @@ namespace Flow.Launcher } } - public T LoadJsonStorage() where T : new() + public T LoadSettingJsonStorage() where T : new() { var type = typeof(T); if (!_pluginJsonStorages.ContainsKey(type)) @@ -154,7 +154,7 @@ namespace Flow.Launcher return ((PluginJsonStorage) _pluginJsonStorages[type]).Load(); } - public void SaveJsonStorage() where T : new() + public void SaveSettingJsonStorage() where T : new() { var type = typeof(T); if (!_pluginJsonStorages.ContainsKey(type)) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index f76946644..a0b443e75 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -24,7 +24,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark { this.context = context; - _settings = context.API.LoadJsonStorage(); + _settings = context.API.LoadSettingJsonStorage(); cachedBookmarks = Bookmarks.LoadAllBookmarks(); } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index fb632c9a1..7de4d30fe 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -33,7 +33,7 @@ namespace Flow.Launcher.Plugin.Caculator public void Init(PluginInitContext context) { Context = context; - _settings = context.API.LoadJsonStorage(); + _settings = context.API.LoadSettingJsonStorage(); _viewModel = new SettingsViewModel(_settings); MagesEngine = new Engine(new Configuration diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index da8590c90..8204e755c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -32,7 +32,7 @@ namespace Flow.Launcher.Plugin.Explorer { Context = context; - Settings = context.API.LoadJsonStorage(); + Settings = context.API.LoadSettingJsonStorage(); viewModel = new SettingsViewModel(context, Settings); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 45519bf5b..92932bf4c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -22,7 +22,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels public void Save() { - Context.API.SaveJsonStorage(); + Context.API.SaveSettingJsonStorage(); } internal void RemoveLinkFromQuickAccess(AccessLink selectedRow) => Settings.QuickAccessLinks.Remove(selectedRow); diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs index bc5c0ef96..f0ef89c82 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs @@ -34,7 +34,7 @@ namespace Flow.Launcher.Plugin.PluginsManager public Task InitAsync(PluginInitContext context) { Context = context; - Settings = context.API.LoadJsonStorage(); + Settings = context.API.LoadSettingJsonStorage(); viewModel = new SettingsViewModel(context, Settings); contextMenu = new ContextMenu(Context); pluginManager = new PluginsManager(Context, Settings); diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 3d9afa68b..5175970fd 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -69,7 +69,7 @@ namespace Flow.Launcher.Plugin.Program { _context = context; - _settings = context.API.LoadJsonStorage(); + _settings = context.API.LoadSettingJsonStorage(); await Task.Yield(); diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index 607231590..bbe29541e 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -272,7 +272,7 @@ namespace Flow.Launcher.Plugin.Shell { this.context = context; context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent; - _settings = context.API.LoadJsonStorage(); + _settings = context.API.LoadSettingJsonStorage(); } bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) diff --git a/Plugins/Flow.Launcher.Plugin.Url/Main.cs b/Plugins/Flow.Launcher.Plugin.Url/Main.cs index 4bf8c6d59..0f4b6c117 100644 --- a/Plugins/Flow.Launcher.Plugin.Url/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Url/Main.cs @@ -118,7 +118,7 @@ namespace Flow.Launcher.Plugin.Url { this.context = context; - _settings = context.API.LoadJsonStorage(); + _settings = context.API.LoadSettingJsonStorage(); } public string GetTranslatedPluginTitle() diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs index 6df2ef220..8d8c84392 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs @@ -168,7 +168,7 @@ namespace Flow.Launcher.Plugin.WebSearch { _context = context; - _settings = _context.API.LoadJsonStorage(); + _settings = _context.API.LoadSettingJsonStorage(); _viewModel = new SettingsViewModel(_settings); var pluginDirectory = _context.CurrentPluginMetadata.PluginDirectory;