mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #393 from Flow-Launcher/PluginJsonStorageSingleInstance
Make PluginJsonStorage in IPublicAPI become single instance per type
This commit is contained in:
commit
b359d709a5
2 changed files with 53 additions and 4 deletions
|
|
@ -165,10 +165,26 @@ namespace Flow.Launcher.Plugin
|
|||
T LoadJsonStorage<T>() where T : new();
|
||||
|
||||
/// <summary>
|
||||
/// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow
|
||||
/// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow.Launcher
|
||||
/// This method will save the original instance loaded with LoadJsonStorage.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for Serialization</typeparam>
|
||||
/// <returns></returns>
|
||||
void SaveJsonStorage<T>(T setting) where T : new();
|
||||
void SaveJsonStorage<T>() where T : new();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for Serialization</typeparam>
|
||||
/// <returns></returns>
|
||||
void SaveJsonStorage<T>(T settings) where T : new();
|
||||
|
||||
/// <summary>
|
||||
/// Backup the JsonStorage you loaded from LoadJsonStorage
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="settings"></param>
|
||||
void BackupJsonStorage<T>() where T : new();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,9 +131,42 @@ namespace Flow.Launcher
|
|||
|
||||
public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName);
|
||||
|
||||
public T LoadJsonStorage<T>() where T : new() => new PluginJsonStorage<T>().Load();
|
||||
private readonly Dictionary<Type, dynamic> PluginJsonStorages = new Dictionary<Type, dynamic>();
|
||||
|
||||
public void SaveJsonStorage<T>(T setting) where T : new() => new PluginJsonStorage<T>(setting).Save();
|
||||
public T LoadJsonStorage<T>() where T : new()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (!PluginJsonStorages.ContainsKey(type))
|
||||
PluginJsonStorages[type] = new PluginJsonStorage<T>();
|
||||
|
||||
return PluginJsonStorages[type].Load();
|
||||
}
|
||||
|
||||
public void SaveJsonStorage<T>() where T : new()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (!PluginJsonStorages.ContainsKey(type))
|
||||
PluginJsonStorages[type] = new PluginJsonStorage<T>();
|
||||
|
||||
PluginJsonStorages[type].Save();
|
||||
}
|
||||
|
||||
public void SaveJsonStorage<T>(T settings) where T : new()
|
||||
{
|
||||
var type = typeof(T);
|
||||
PluginJsonStorages[type] = new PluginJsonStorage<T>(settings);
|
||||
|
||||
PluginJsonStorages[type].Save();
|
||||
}
|
||||
|
||||
public void BackupJsonStorage<T>() 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();
|
||||
}
|
||||
|
||||
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue