diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 8c9fd2eb964..e2c009ee3aa 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -51,6 +51,7 @@ public static void Save() var savable = plugin.Plugin as ISavable; savable?.Save(); } + API.SavePluginSettings(); } public static async Task ReloadData() diff --git a/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs index 03a0206bbe5..ec7a388040f 100644 --- a/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs @@ -8,7 +8,7 @@ namespace Flow.Launcher.Infrastructure.Storage { - public class FlowLauncherJsonStorage : JsonStrorage where T : new() + public class FlowLauncherJsonStorage : JsonStorage where T : new() { public FlowLauncherJsonStorage() { diff --git a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs index 833ec087d6e..43d19bea865 100644 --- a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs @@ -9,7 +9,7 @@ namespace Flow.Launcher.Infrastructure.Storage /// /// Serialize object using json format. /// - public class JsonStrorage where T : new() + public class JsonStorage where T : new() { protected T _data; // need a new directory name @@ -23,10 +23,10 @@ public T Load() { if (File.Exists(FilePath)) { - var searlized = File.ReadAllText(FilePath); - if (!string.IsNullOrWhiteSpace(searlized)) + var serialized = File.ReadAllText(FilePath); + if (!string.IsNullOrWhiteSpace(serialized)) { - Deserialize(searlized); + Deserialize(serialized); } else { @@ -40,16 +40,16 @@ public T Load() return _data.NonNull(); } - private void Deserialize(string searlized) + private void Deserialize(string serialized) { try { - _data = JsonSerializer.Deserialize(searlized); + _data = JsonSerializer.Deserialize(serialized); } catch (JsonException e) { LoadDefault(); - Log.Exception($"|JsonStrorage.Deserialize|Deserialize error for json <{FilePath}>", e); + Log.Exception($"|JsonStorage.Deserialize|Deserialize error for json <{FilePath}>", e); } if (_data == null) diff --git a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs index ca7c454c4f5..c26aef95dfc 100644 --- a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs @@ -3,13 +3,13 @@ namespace Flow.Launcher.Infrastructure.Storage { - public class PluginJsonStorage :JsonStrorage where T : new() + public class PluginJsonStorage :JsonStorage where T : new() { public PluginJsonStorage() { - // C# releated, add python releated below + // C# related, add python related below var dataType = typeof(T); - var assemblyName = typeof(T).Assembly.GetName().Name; + var assemblyName = dataType.Assembly.GetName().Name; DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, assemblyName); Helper.ValidateDirectory(DirectoryPath); diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index cd903898a3b..d9cdf5581d0 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -30,10 +30,15 @@ public interface IPublicAPI void RestartApp(); /// - /// Save all Flow Launcher settings + /// Save everything, all of Flow Launcher and plugins' data and settings /// void SaveAppAllSettings(); + /// + /// Save all Flow's plugins settings + /// + void SavePluginSettings(); + /// /// Reloads any Plugins that have the /// IReloadable implemented. It refeshes @@ -165,33 +170,20 @@ public interface IPublicAPI 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 type that has called LoadSettingJsonStorage or SaveSettingJsonStorage previously. /// /// 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 - /// - /// Type for Serialization - /// - void SaveJsonStorage(T settings) where T : new(); - - /// - /// Backup the JsonStorage you loaded from LoadJsonStorage - /// - /// - /// - void BackupJsonStorage() where T : new(); + void SaveSettingJsonStorage() where T : new(); } } diff --git a/Flow.Launcher.Plugin/Interfaces/ISavable.cs b/Flow.Launcher.Plugin/Interfaces/ISavable.cs index 7c1110e0e2d..6f408dc2ee9 100644 --- a/Flow.Launcher.Plugin/Interfaces/ISavable.cs +++ b/Flow.Launcher.Plugin/Interfaces/ISavable.cs @@ -1,8 +1,9 @@ namespace Flow.Launcher.Plugin { /// - /// Save plugin settings/cache, - /// todo should be merged into a abstract class intead of seperate interface + /// Save addtional plugin data. Inherit this interface if additional data e.g. cache needs to be saved, + /// Otherwise if LoadSettingJsonStorage or SaveSettingJsonStorage has been callded, + /// plugin settings will be automatically saved (see Flow.Launcher/PublicAPIInstance.SavePluginSettings) by Flow /// public interface ISavable { diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index edc3b9a3e36..b3f7b8d4fd5 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -76,23 +76,25 @@ public void RestartApp() public void SaveAppAllSettings() { + 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); }); } @@ -113,61 +115,70 @@ public void OpenSettingDialog() 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 Dictionary(); + private readonly Dictionary _pluginJsonStorages = new(); - public T LoadJsonStorage() where T : new() + public void SavePluginSettings() { - var type = typeof(T); - if (!PluginJsonStorages.ContainsKey(type)) - PluginJsonStorages[type] = new PluginJsonStorage(); - - return PluginJsonStorages[type].Load(); + foreach (var value in _pluginJsonStorages.Values) + { + var method = value.GetType().GetMethod("Save"); + method?.Invoke(value, null); + } } - public void SaveJsonStorage() where T : new() + public T LoadSettingJsonStorage() where T : new() { var type = typeof(T); - if (!PluginJsonStorages.ContainsKey(type)) - PluginJsonStorages[type] = new PluginJsonStorage(); + if (!_pluginJsonStorages.ContainsKey(type)) + _pluginJsonStorages[type] = new PluginJsonStorage(); - PluginJsonStorages[type].Save(); + return ((PluginJsonStorage) _pluginJsonStorages[type]).Load(); } - public void SaveJsonStorage(T settings) where T : new() + public void SaveSettingJsonStorage() where T : new() { var type = typeof(T); - PluginJsonStorages[type] = new PluginJsonStorage(settings); + if (!_pluginJsonStorages.ContainsKey(type)) + _pluginJsonStorages[type] = new PluginJsonStorage(); - PluginJsonStorages[type].Save(); + ((PluginJsonStorage) _pluginJsonStorages[type]).Save(); } - public void BackupJsonStorage() where T : new() + public void SaveJsonStorage(T settings) where T : new() { var type = typeof(T); - if (!PluginJsonStorages.ContainsKey(type)) - throw new InvalidOperationException("You haven't registered the JsonStorage for specific Type"); + _pluginJsonStorages[type] = new PluginJsonStorage(settings); - PluginJsonStorages[type].BackupOriginFile(); + ((PluginJsonStorage) _pluginJsonStorages[type]).Save(); } public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; @@ -180,11 +191,12 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe { if (GlobalKeyboardEvent != null) { - return GlobalKeyboardEvent((int)keyevent, vkcode, state); + return GlobalKeyboardEvent((int) keyevent, vkcode, state); } + return true; } #endregion } -} +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index 5bff0e182fc..a0b443e7550 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -12,21 +12,19 @@ namespace Flow.Launcher.Plugin.BrowserBookmark { - public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable, IContextMenu + public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu { private PluginInitContext context; private List cachedBookmarks = new List(); private Settings _settings { get; set;} - private PluginJsonStorage _storage { get; set;} public void Init(PluginInitContext context) { this.context = context; - _storage = new PluginJsonStorage(); - _settings = _storage.Load(); + _settings = context.API.LoadSettingJsonStorage(); cachedBookmarks = Bookmarks.LoadAllBookmarks(); } @@ -113,11 +111,6 @@ public Control CreateSettingPanel() return new SettingsControl(_settings); } - public void Save() - { - _storage.Save(); - } - public List LoadContextMenus(Result selectedResult) { return new List() { diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/plugin.json b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/plugin.json index 7c4b619890b..884621b9f65 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/plugin.json @@ -4,7 +4,7 @@ "Name": "Browser Bookmarks", "Description": "Search your browser bookmarks", "Author": "qianlifeng, Ioannis G.", - "Version": "1.4.3", + "Version": "1.4.4", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.BrowserBookmark.dll", diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 3c60bbf5a76..7de4d30fef5 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -12,7 +12,7 @@ namespace Flow.Launcher.Plugin.Caculator { - public class Main : IPlugin, IPluginI18n, ISavable, ISettingProvider + public class Main : IPlugin, IPluginI18n, ISettingProvider { private static readonly Regex RegValidExpressChar = new Regex( @"^(" + @@ -30,17 +30,11 @@ public class Main : IPlugin, IPluginI18n, ISavable, ISettingProvider private static Settings _settings; private static SettingsViewModel _viewModel; - static Main() - { - - } - public void Init(PluginInitContext context) { Context = context; - - _viewModel = new SettingsViewModel(); - _settings = _viewModel.Settings; + _settings = context.API.LoadSettingJsonStorage(); + _viewModel = new SettingsViewModel(_settings); MagesEngine = new Engine(new Configuration { @@ -187,10 +181,5 @@ public Control CreateSettingPanel() { return new CalculatorSettings(_viewModel); } - - public void Save() - { - _viewModel.Save(); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs index bc5433254c5..9ee95e84020 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs @@ -8,23 +8,15 @@ namespace Flow.Launcher.Plugin.Caculator.ViewModels { - public class SettingsViewModel : BaseModel, ISavable + public class SettingsViewModel : BaseModel { - private readonly PluginJsonStorage _storage; - - public SettingsViewModel() + public SettingsViewModel(Settings settings) { - _storage = new PluginJsonStorage(); - Settings = _storage.Load(); + Settings = settings; } - public Settings Settings { get; set; } + public Settings Settings { get; init; } public IEnumerable MaxDecimalPlacesRange => Enumerable.Range(1, 20); - - public void Save() - { - _storage.Save(); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json b/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json index f7a1304282d..faf899846e1 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json @@ -4,7 +4,7 @@ "Name": "Calculator", "Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)", "Author": "cxfksword", - "Version": "1.1.7", + "Version": "1.1.8", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll", diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index ae7bf57d219..8204e755c8f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -11,7 +11,7 @@ namespace Flow.Launcher.Plugin.Explorer { - public class Main : ISettingProvider, IAsyncPlugin, ISavable, IContextMenu, IPluginI18n + public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n { internal PluginInitContext Context { get; set; } @@ -31,9 +31,11 @@ public Control CreateSettingPanel() public async Task InitAsync(PluginInitContext context) { Context = context; - viewModel = new SettingsViewModel(context); - await viewModel.LoadStorage(); - Settings = viewModel.Settings; + + Settings = context.API.LoadSettingJsonStorage(); + + viewModel = new SettingsViewModel(context, Settings); + // as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards. if (Settings.QuickFolderAccessLinks.Any()) @@ -57,11 +59,6 @@ public async Task> QueryAsync(Query query, CancellationToken token) return await searchManager.SearchAsync(query, token); } - public void Save() - { - viewModel.Save(); - } - public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("plugin_explorer_plugin_name"); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 791c06b66f4..92932bf4c6b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -9,27 +9,20 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels { public class SettingsViewModel { - private readonly PluginJsonStorage storage; - internal Settings Settings { get; set; } internal PluginInitContext Context { get; set; } - public SettingsViewModel(PluginInitContext context) + public SettingsViewModel(PluginInitContext context, Settings settings) { Context = context; - storage = new PluginJsonStorage(); - Settings = storage.Load(); + Settings = settings; } - public Task LoadStorage() - { - return Task.Run(() => Settings = storage.Load()); - } public void Save() { - storage.Save(); + Context.API.SaveSettingJsonStorage(); } internal void RemoveLinkFromQuickAccess(AccessLink selectedRow) => Settings.QuickAccessLinks.Remove(selectedRow); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index dd88611acbc..6be1ed95d45 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.7.6", + "Version": "1.7.7", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs index 3707beee2cb..f0ef89c8261 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs @@ -8,10 +8,11 @@ using System; using System.Threading.Tasks; using System.Threading; +using System.Windows; namespace Flow.Launcher.Plugin.PluginsManager { - public class Main : ISettingProvider, IAsyncPlugin, ISavable, IContextMenu, IPluginI18n, IAsyncReloadable + public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, IAsyncReloadable { internal PluginInitContext Context { get; set; } @@ -33,8 +34,8 @@ public Control CreateSettingPanel() public Task InitAsync(PluginInitContext context) { Context = context; - viewModel = new SettingsViewModel(context); - Settings = viewModel.Settings; + Settings = context.API.LoadSettingJsonStorage(); + viewModel = new SettingsViewModel(context, Settings); contextMenu = new ContextMenu(Context); pluginManager = new PluginsManager(Context, Settings); _ = pluginManager.UpdateManifest().ContinueWith(_ => @@ -78,11 +79,6 @@ var s when s.StartsWith(Settings.HotkeyUpdate) => await pluginManager.RequestUpd }; } - public void Save() - { - viewModel.Save(); - } - public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("plugin_pluginsmanager_plugin_name"); diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs index f3cf117d33f..8ca4c614a45 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs @@ -3,24 +3,16 @@ namespace Flow.Launcher.Plugin.PluginsManager.ViewModels { - public class SettingsViewModel + internal class SettingsViewModel { - private readonly PluginJsonStorage storage; - internal Settings Settings { get; set; } internal PluginInitContext Context { get; set; } - public SettingsViewModel(PluginInitContext context) + public SettingsViewModel(PluginInitContext context, Settings settings) { Context = context; - storage = new PluginJsonStorage(); - Settings = storage.Load(); - } - - public void Save() - { - storage.Save(); + Settings = settings; } } } diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs index 14204eda930..703682e074f 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs @@ -10,7 +10,7 @@ public partial class PluginsManagerSettings { private readonly SettingsViewModel viewModel; - public PluginsManagerSettings(SettingsViewModel viewModel) + internal PluginsManagerSettings(SettingsViewModel viewModel) { InitializeComponent(); diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json index 576f1e838d7..0a28d8acd0f 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/plugin.json @@ -6,7 +6,7 @@ "Name": "Plugins Manager", "Description": "Management of installing, uninstalling or updating Flow Launcher plugins", "Author": "Jeremy Wu", - "Version": "1.8.0", + "Version": "1.8.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll", diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 0f6968092b2..5175970fd41 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -25,16 +25,14 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I private static BinaryStorage _win32Storage; private static BinaryStorage _uwpStorage; - private readonly PluginJsonStorage _settingsStorage; public Main() { - _settingsStorage = new PluginJsonStorage(); + } public void Save() { - _settingsStorage.Save(); _win32Storage.Save(_win32s); _uwpStorage.Save(_uwps); } @@ -71,7 +69,7 @@ public async Task InitAsync(PluginInitContext context) { _context = context; - _settings = _settingsStorage.Load(); + _settings = context.API.LoadSettingJsonStorage(); await Task.Yield(); diff --git a/Plugins/Flow.Launcher.Plugin.Program/plugin.json b/Plugins/Flow.Launcher.Plugin.Program/plugin.json index 89243a8435c..5838a8eb63a 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Program/plugin.json @@ -4,7 +4,7 @@ "Name": "Program", "Description": "Search programs in Flow.Launcher", "Author": "qianlifeng", - "Version": "1.4.5", + "Version": "1.4.6", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Program.dll", diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index d83f59be147..71da60ff74d 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -18,27 +18,14 @@ namespace Flow.Launcher.Plugin.Shell { - public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable + public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu { private const string Image = "Images/shell.png"; private PluginInitContext context; private bool _winRStroked; private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator(new InputSimulator()); - private readonly Settings _settings; - private readonly PluginJsonStorage _storage; - - public Main() - { - _storage = new PluginJsonStorage(); - _settings = _storage.Load(); - } - - public void Save() - { - _storage.Save(); - } - + private Settings _settings; public List Query(Query query) { @@ -285,6 +272,7 @@ public void Init(PluginInitContext context) { this.context = context; context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent; + _settings = context.API.LoadSettingJsonStorage(); } bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/plugin.json b/Plugins/Flow.Launcher.Plugin.Shell/plugin.json index 4d53c211e77..cbc715b6bec 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Shell/plugin.json @@ -4,7 +4,7 @@ "Name": "Shell", "Description": "Provide executing commands from Flow Launcher", "Author": "qianlifeng", - "Version": "1.4.0", + "Version": "1.4.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll", diff --git a/Plugins/Flow.Launcher.Plugin.Url/Main.cs b/Plugins/Flow.Launcher.Plugin.Url/Main.cs index 60d7972d27b..0f4b6c11793 100644 --- a/Plugins/Flow.Launcher.Plugin.Url/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Url/Main.cs @@ -7,7 +7,7 @@ namespace Flow.Launcher.Plugin.Url { - public class Main : ISettingProvider,IPlugin, IPluginI18n, ISavable + public class Main : ISettingProvider,IPlugin, IPluginI18n { //based on https://gist.github.com/dperini/729294 private const string urlPattern = "^" + @@ -44,20 +44,9 @@ public class Main : ISettingProvider,IPlugin, IPluginI18n, ISavable "$"; Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); private PluginInitContext context; - private readonly Settings _settings; - private readonly PluginJsonStorage _storage; - - public Main() - { - _storage = new PluginJsonStorage(); - _settings = _storage.Load(); - } - - public void Save() - { - _storage.Save(); - } + private Settings _settings; + public List Query(Query query) { var raw = query.Search; @@ -128,6 +117,8 @@ public bool IsURL(string raw) public void Init(PluginInitContext context) { this.context = context; + + _settings = context.API.LoadSettingJsonStorage(); } public string GetTranslatedPluginTitle() diff --git a/Plugins/Flow.Launcher.Plugin.Url/plugin.json b/Plugins/Flow.Launcher.Plugin.Url/plugin.json index 573bf421be7..fd150b9e49b 100644 --- a/Plugins/Flow.Launcher.Plugin.Url/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Url/plugin.json @@ -4,7 +4,7 @@ "Name": "URL", "Description": "Open the typed URL from Flow Launcher", "Author": "qianlifeng", - "Version": "1.1.5", + "Version": "1.1.6", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Url.dll", diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs index 5235f3fbec3..8d8c84392de 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs @@ -14,12 +14,12 @@ namespace Flow.Launcher.Plugin.WebSearch { - public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, ISavable, IResultUpdated + public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, IResultUpdated { private PluginInitContext _context; - private readonly Settings _settings; - private readonly SettingsViewModel _viewModel; + private Settings _settings; + private SettingsViewModel _viewModel; internal const string Images = "Images"; internal static string DefaultImagesDirectory; @@ -31,10 +31,6 @@ public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, ISavable, IResu private readonly string SearchSourceGlobalPluginWildCardSign = "*"; - public void Save() - { - _viewModel.Save(); - } public async Task> QueryAsync(Query query, CancellationToken token) { @@ -164,12 +160,6 @@ private async Task> SuggestionsAsync(string keyword, string return new List(); } - public Main() - { - _viewModel = new SettingsViewModel(); - _settings = _viewModel.Settings; - } - public Task InitAsync(PluginInitContext context) { return Task.Run(Init); @@ -177,6 +167,10 @@ public Task InitAsync(PluginInitContext context) void Init() { _context = context; + + _settings = _context.API.LoadSettingJsonStorage(); + _viewModel = new SettingsViewModel(_settings); + var pluginDirectory = _context.CurrentPluginMetadata.PluginDirectory; var bundledImagesDirectory = Path.Combine(pluginDirectory, Images); diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs index 5943b187e47..a2538893bc9 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs @@ -6,13 +6,12 @@ public class SettingsViewModel { private readonly PluginJsonStorage _storage; - public SettingsViewModel() + public SettingsViewModel(Settings settings) { - _storage = new PluginJsonStorage(); - Settings = _storage.Load(); + Settings = settings; } - public Settings Settings { get; set; } + public Settings Settings { get; } public void Save() { diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json index ea8b081c8f8..705f1529de3 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json @@ -26,7 +26,7 @@ "Name": "Web Searches", "Description": "Provide the web search ability", "Author": "qianlifeng", - "Version": "1.3.8", + "Version": "1.3.9", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",