diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs
index cd903898a..6833bc6b9 100644
--- a/Flow.Launcher.Plugin/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/IPublicAPI.cs
@@ -186,12 +186,5 @@ namespace Flow.Launcher.Plugin
/// Type for Serialization
///
void SaveJsonStorage(T settings) where T : new();
-
- ///
- /// Backup the JsonStorage you loaded from LoadJsonStorage
- ///
- ///
- ///
- void BackupJsonStorage() where T : new();
}
}
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index edc3b9a3e..8b07a7e74 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -133,7 +133,7 @@ namespace Flow.Launcher
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 Dictionary();
public T LoadJsonStorage() where T : new()
{
@@ -141,7 +141,7 @@ namespace Flow.Launcher
if (!PluginJsonStorages.ContainsKey(type))
PluginJsonStorages[type] = new PluginJsonStorage();
- return PluginJsonStorages[type].Load();
+ return ((PluginJsonStorage) PluginJsonStorages[type]).Load();
}
public void SaveJsonStorage() where T : new()
@@ -150,7 +150,7 @@ namespace Flow.Launcher
if (!PluginJsonStorages.ContainsKey(type))
PluginJsonStorages[type] = new PluginJsonStorage();
- PluginJsonStorages[type].Save();
+ ((PluginJsonStorage) PluginJsonStorages[type]).Save();
}
public void SaveJsonStorage(T settings) where T : new()
@@ -158,16 +158,7 @@ namespace Flow.Launcher
var type = typeof(T);
PluginJsonStorages[type] = new PluginJsonStorage(settings);
- PluginJsonStorages[type].Save();
- }
-
- public void BackupJsonStorage() 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].BackupOriginFile();
+ ((PluginJsonStorage) PluginJsonStorages[type]).Save();
}
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
index 5bff0e182..fea672596 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
@@ -12,25 +12,28 @@ using Flow.Launcher.Plugin.SharedCommands;
namespace Flow.Launcher.Plugin.BrowserBookmark
{
- public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable, IContextMenu
+ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, ISavable
{
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.LoadJsonStorage();
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
+ public void Save()
+ {
+ context.API.SaveJsonStorage();
+ }
+
public List Query(Query query)
{
string param = query.Search.TrimStart();
@@ -113,11 +116,6 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
return new SettingsControl(_settings);
}
- public void Save()
- {
- _storage.Save();
- }
-
public List LoadContextMenus(Result selectedResult)
{
return new List() {
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
index ae7bf57d2..da8590c90 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
@@ -11,7 +11,7 @@ using System.Windows.Controls;
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 @@ namespace Flow.Launcher.Plugin.Explorer
public async Task InitAsync(PluginInitContext context)
{
Context = context;
- viewModel = new SettingsViewModel(context);
- await viewModel.LoadStorage();
- Settings = viewModel.Settings;
+
+ Settings = context.API.LoadJsonStorage();
+
+ 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 @@ namespace Flow.Launcher.Plugin.Explorer
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 791c06b66..45519bf5b 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.SaveJsonStorage();
}
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 3707beee2..f8f5d2378 100644
--- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Main.cs
@@ -8,6 +8,7 @@ using Flow.Launcher.Infrastructure;
using System;
using System.Threading.Tasks;
using System.Threading;
+using System.Windows;
namespace Flow.Launcher.Plugin.PluginsManager
{
@@ -33,8 +34,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
public Task InitAsync(PluginInitContext context)
{
Context = context;
- viewModel = new SettingsViewModel(context);
- Settings = viewModel.Settings;
+ Settings = context.API.LoadJsonStorage();
+ viewModel = new SettingsViewModel(context, Settings);
contextMenu = new ContextMenu(Context);
pluginManager = new PluginsManager(Context, Settings);
_ = pluginManager.UpdateManifest().ContinueWith(_ =>
diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs
index f3cf117d3..aab7c40b5 100644
--- a/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs
+++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs
@@ -3,7 +3,7 @@ using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
{
- public class SettingsViewModel
+ internal class SettingsViewModel
{
private readonly PluginJsonStorage storage;
@@ -11,11 +11,11 @@ namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
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 void Save()
diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Views/PluginsManagerSettings.xaml.cs
index 14204eda9..703682e07 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 @@ namespace Flow.Launcher.Plugin.PluginsManager.Views
{
private readonly SettingsViewModel viewModel;
- public PluginsManagerSettings(SettingsViewModel viewModel)
+ internal PluginsManagerSettings(SettingsViewModel viewModel)
{
InitializeComponent();
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 0f6968092..8efd4bbd9 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -25,16 +25,15 @@ namespace Flow.Launcher.Plugin.Program
private static BinaryStorage _win32Storage;
private static BinaryStorage _uwpStorage;
- private readonly PluginJsonStorage _settingsStorage;
public Main()
{
- _settingsStorage = new PluginJsonStorage();
+
}
public void Save()
{
- _settingsStorage.Save();
+ _context.API.SaveJsonStorage();
_win32Storage.Save(_win32s);
_uwpStorage.Save(_uwps);
}
@@ -71,7 +70,7 @@ namespace Flow.Launcher.Plugin.Program
{
_context = context;
- _settings = _settingsStorage.Load();
+ _settings = context.API.LoadJsonStorage();
await Task.Yield();
diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs
index 4ec180793..f38ac1932 100644
--- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs
@@ -25,18 +25,11 @@ namespace Flow.Launcher.Plugin.Shell
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();
- }
+ private Settings _settings;
public void Save()
{
- _storage.Save();
+ context.API.SaveJsonStorage();
}
@@ -285,6 +278,7 @@ namespace Flow.Launcher.Plugin.Shell
{
this.context = context;
context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent;
+ _settings = context.API.LoadJsonStorage();
}
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 60d7972d2..d2189ef49 100644
--- a/Plugins/Flow.Launcher.Plugin.Url/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Url/Main.cs
@@ -44,18 +44,12 @@ namespace Flow.Launcher.Plugin.Url
"$";
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
private PluginInitContext context;
- private readonly Settings _settings;
- private readonly PluginJsonStorage _storage;
+ private Settings _settings;
- public Main()
- {
- _storage = new PluginJsonStorage();
- _settings = _storage.Load();
- }
public void Save()
{
- _storage.Save();
+ context.API.SaveJsonStorage();
}
public List Query(Query query)
@@ -128,6 +122,8 @@ namespace Flow.Launcher.Plugin.Url
public void Init(PluginInitContext context)
{
this.context = context;
+
+ _settings = context.API.LoadJsonStorage();
}
public string GetTranslatedPluginTitle()