diff --git a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs index f0e4a79fc..37cfec252 100644 --- a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs @@ -12,7 +12,7 @@ namespace Flow.Launcher.Infrastructure.Storage public class JsonStrorage where T : new() { private readonly JsonSerializerOptions _serializerSettings; - private T _data; + protected T _data; // need a new directory name public const string DirectoryName = "Settings"; public const string FileSuffix = ".json"; diff --git a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs index 5418e1837..ca7c454c4 100644 --- a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs @@ -15,5 +15,10 @@ namespace Flow.Launcher.Infrastructure.Storage FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}"); } + + public PluginJsonStorage(T data) : this() + { + _data = data; + } } } diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index dd73eb0e5..2a69a2495 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -3,6 +3,7 @@ using JetBrains.Annotations; using System; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -100,5 +101,16 @@ namespace Flow.Launcher.Plugin void RemoveActionKeyword(string pluginId, string oldActionKeyword); + void LogDebug(string className, string message, [CallerMemberName] string methodName = ""); + + void LogInfo(string className, string message, [CallerMemberName] string methodName = ""); + + void LogWarn(string className, string message, [CallerMemberName] string methodName = ""); + + void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = ""); + + T LoadJsonStorage(PluginMetadata metadata) where T : new(); + + void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new(); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 0afa67d1a..9c36a709e 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -18,6 +18,9 @@ using System.Threading; using System.IO; using Flow.Launcher.Infrastructure.Http; using JetBrains.Annotations; +using System.Runtime.CompilerServices; +using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Storage; namespace Flow.Launcher { @@ -160,6 +163,41 @@ namespace Flow.Launcher { PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword); } + + + 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 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 T LoadJsonStorage(PluginMetadata metadata) where T : new() + { + var storage = new PluginJsonStorage(); + return storage.Load(); + } + + public void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new() + { + var storage = new PluginJsonStorage(setting); + storage.Save(); + } + + #endregion #region Private Methods @@ -173,6 +211,7 @@ namespace Flow.Launcher return true; } + #endregion } }