Add SavePluginSettings API, and call that api in PluginManager.Save();

This commit is contained in:
张弘韬 2021-05-13 20:49:41 +08:00
parent d84eff7712
commit 20ba2b2d23
3 changed files with 35 additions and 18 deletions

View file

@ -51,6 +51,7 @@ namespace Flow.Launcher.Core.Plugin
var savable = plugin.Plugin as ISavable; var savable = plugin.Plugin as ISavable;
savable?.Save(); savable?.Save();
} }
API.SavePluginSettings();
} }
public static async Task ReloadData() public static async Task ReloadData()

View file

@ -34,6 +34,11 @@ namespace Flow.Launcher.Plugin
/// </summary> /// </summary>
void SaveAppAllSettings(); void SaveAppAllSettings();
/// <summary>
/// Save Flow's plugins settings
/// </summary>
void SavePluginSettings();
/// <summary> /// <summary>
/// Reloads any Plugins that have the /// Reloads any Plugins that have the
/// IReloadable implemented. It refeshes /// IReloadable implemented. It refeshes

View file

@ -76,24 +76,25 @@ namespace Flow.Launcher
public void SaveAppAllSettings() public void SaveAppAllSettings()
{ {
SaveAllJsonStorage(); SavePluginSettings();
_mainVM.Save(); _mainVM.Save();
_settingsVM.Save(); _settingsVM.Save();
PluginManager.Save();
ImageLoader.Save(); ImageLoader.Save();
} }
public Task ReloadAllPluginData() => PluginManager.ReloadData(); 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) public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
{ {
Application.Current.Dispatcher.Invoke(() => 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); msg.Show(title, subTitle, iconPath);
}); });
} }
@ -114,29 +115,38 @@ namespace Flow.Launcher
public List<PluginPair> GetAllPlugins() => PluginManager.AllPlugins.ToList(); public List<PluginPair> 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<string> HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url); public Task<string> HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url);
public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url); public Task<Stream> 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<Type, object> _pluginJsonStorages = new(); private readonly Dictionary<Type, object> _pluginJsonStorages = new();
private void SaveAllJsonStorage() public void SavePluginSettings()
{ {
foreach (var value in _pluginJsonStorages.Values) foreach (var value in _pluginJsonStorages.Values)
{ {
@ -181,8 +191,9 @@ namespace Flow.Launcher
{ {
if (GlobalKeyboardEvent != null) if (GlobalKeyboardEvent != null)
{ {
return GlobalKeyboardEvent((int)keyevent, vkcode, state); return GlobalKeyboardEvent((int) keyevent, vkcode, state);
} }
return true; return true;
} }