From 20ba2b2d2377773118cd84db1283008df31ee5dc 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 20:49:41 +0800 Subject: [PATCH] Add SavePluginSettings API, and call that api in PluginManager.Save(); --- Flow.Launcher.Core/Plugin/PluginManager.cs | 1 + Flow.Launcher.Plugin/IPublicAPI.cs | 5 +++ Flow.Launcher/PublicAPIInstance.cs | 47 +++++++++++++--------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 8c9fd2eb9..e2c009ee3 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -51,6 +51,7 @@ namespace Flow.Launcher.Core.Plugin var savable = plugin.Plugin as ISavable; savable?.Save(); } + API.SavePluginSettings(); } public static async Task ReloadData() diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index bdd3e70a2..c9f11555d 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -34,6 +34,11 @@ namespace Flow.Launcher.Plugin /// void SaveAppAllSettings(); + /// + /// Save Flow's plugins settings + /// + void SavePluginSettings(); + /// /// Reloads any Plugins that have the /// IReloadable implemented. It refeshes diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 058506e3a..b3f7b8d4f 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -76,24 +76,25 @@ namespace Flow.Launcher public void SaveAppAllSettings() { - SaveAllJsonStorage(); + SavePluginSettings(); _mainVM.Save(); _settingsVM.Save(); - PluginManager.Save(); ImageLoader.Save(); } public Task ReloadAllPluginData() => PluginManager.ReloadData(); - public void ShowMsgError(string title, string subTitle = "") => ShowMsg(title, subTitle, Constant.ErrorIcon, true); + public void ShowMsgError(string title, string subTitle = "") => + ShowMsg(title, subTitle, Constant.ErrorIcon, true); - public void ShowMsg(string title, string subTitle = "", string iconPath = "") => ShowMsg(title, subTitle, iconPath, true); + public void ShowMsg(string title, string subTitle = "", string iconPath = "") => + ShowMsg(title, subTitle, iconPath, true); public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true) { Application.Current.Dispatcher.Invoke(() => { - var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg(); + var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg(); msg.Show(title, subTitle, iconPath); }); } @@ -114,29 +115,38 @@ namespace Flow.Launcher public List GetAllPlugins() => PluginManager.AllPlugins.ToList(); - public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); + public MatchResult FuzzySearch(string query, string stringToCompare) => + StringMatcher.FuzzySearch(query, stringToCompare); public Task HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url); - public Task HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url); + public Task HttpGetStreamAsync(string url, CancellationToken token = default) => + Http.GetStreamAsync(url); - public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default) => Http.DownloadAsync(url, filePath, token); + public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, + CancellationToken token = default) => Http.DownloadAsync(url, filePath, token); - public void AddActionKeyword(string pluginId, string newActionKeyword) => PluginManager.AddActionKeyword(pluginId, newActionKeyword); + public void AddActionKeyword(string pluginId, string newActionKeyword) => + PluginManager.AddActionKeyword(pluginId, newActionKeyword); - public void RemoveActionKeyword(string pluginId, string oldActionKeyword) => PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword); + public void RemoveActionKeyword(string pluginId, string oldActionKeyword) => + PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword); - public void LogDebug(string className, string message, [CallerMemberName] string methodName = "") => Log.Debug(className, message, methodName); + public void LogDebug(string className, string message, [CallerMemberName] string methodName = "") => + Log.Debug(className, message, methodName); - public void LogInfo(string className, string message, [CallerMemberName] string methodName = "") => Log.Info(className, message, methodName); + public void LogInfo(string className, string message, [CallerMemberName] string methodName = "") => + Log.Info(className, message, methodName); - public void LogWarn(string className, string message, [CallerMemberName] string methodName = "") => Log.Warn(className, message, methodName); + public void LogWarn(string className, string message, [CallerMemberName] string methodName = "") => + Log.Warn(className, message, methodName); - public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName); + public void LogException(string className, string message, Exception e, + [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName); private readonly Dictionary _pluginJsonStorages = new(); - private void SaveAllJsonStorage() + public void SavePluginSettings() { foreach (var value in _pluginJsonStorages.Values) { @@ -144,7 +154,7 @@ namespace Flow.Launcher method?.Invoke(value, null); } } - + public T LoadSettingJsonStorage() where T : new() { var type = typeof(T); @@ -181,11 +191,12 @@ namespace Flow.Launcher { if (GlobalKeyboardEvent != null) { - return GlobalKeyboardEvent((int)keyevent, vkcode, state); + return GlobalKeyboardEvent((int) keyevent, vkcode, state); } + return true; } #endregion } -} +} \ No newline at end of file