Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Flow.Launcher.Plugin/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,26 @@ public interface IPublicAPI
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();
}
}
37 changes: 35 additions & 2 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,42 @@ public void OpenSettingDialog()

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;

Expand Down