From f8557da336171ddb738715d700e70dca4bf2a5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 18:08:30 +0800 Subject: [PATCH 1/6] add Logs, LoadJsonStorage, SaveJsonStorage to IPublicAPI --- .../Storage/JsonStorage.cs | 2 +- .../Storage/PluginJsonStorage.cs | 5 +++ Flow.Launcher.Plugin/IPublicAPI.cs | 12 ++++++ Flow.Launcher/PublicAPIInstance.cs | 39 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs index f0e4a79fcf6..37cfec25258 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 5418e18371e..ca7c454c4f5 100644 --- a/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs @@ -15,5 +15,10 @@ public PluginJsonStorage() 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 dd73eb0e523..2a69a2495ce 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -100,5 +101,16 @@ public interface IPublicAPI 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 0afa67d1a97..9c36a709ee8 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -18,6 +18,9 @@ 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 @@ 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 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 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe return true; } + #endregion } } From 9fb44e6002d62227ffef1828c6e33c85a2ad6758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 18:12:57 +0800 Subject: [PATCH 2/6] format code --- Flow.Launcher/PublicAPIInstance.cs | 97 ++++++------------------------ 1 file changed, 19 insertions(+), 78 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 9c36a709ee8..967cf1bf7c8 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -70,15 +70,9 @@ public void RestartApp() UpdateManager.RestartApp(Constant.ApplicationFileName); } - public void RestarApp() - { - RestartApp(); - } + public void RestarApp() => RestartApp(); - public void CheckForNewUpdate() - { - _settingsVM.UpdateApp(); - } + public void CheckForNewUpdate() => _settingsVM.UpdateApp(); public void SaveAppAllSettings() { @@ -88,15 +82,9 @@ public void SaveAppAllSettings() ImageLoader.Save(); } - public Task ReloadAllPluginData() - { - return PluginManager.ReloadData(); - } + public Task ReloadAllPluginData() => PluginManager.ReloadData(); - 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) { @@ -115,87 +103,40 @@ public void OpenSettingDialog() }); } - public void StartLoadingBar() - { - _mainVM.ProgressBarVisibility = Visibility.Visible; - } + public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible; - public void StopLoadingBar() - { - _mainVM.ProgressBarVisibility = Visibility.Collapsed; - } + public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed; - public string GetTranslation(string key) - { - return InternationalizationManager.Instance.GetTranslation(key); - } + public string GetTranslation(string key) => InternationalizationManager.Instance.GetTranslation(key); - public List GetAllPlugins() - { - return PluginManager.AllPlugins.ToList(); - } + public List GetAllPlugins() => PluginManager.AllPlugins.ToList(); public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); - public Task HttpGetStringAsync(string url, CancellationToken token = default) - { - return Http.GetAsync(url); - } + public Task HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url); - public Task HttpGetStreamAsync(string url, CancellationToken token = default) - { - return Http.GetStreamAsync(url); - } + public Task HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url); - public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath) - { - return Http.DownloadAsync(url, filePath); - } + public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath) => Http.DownloadAsync(url, filePath); - 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); - public T LoadJsonStorage(PluginMetadata metadata) where T : new() - { - var storage = new PluginJsonStorage(); - return storage.Load(); - } + public T LoadJsonStorage(PluginMetadata metadata) where T : new() => new PluginJsonStorage().Load(); - public void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new() - { - var storage = new PluginJsonStorage(setting); - storage.Save(); - } + public void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new() => new PluginJsonStorage(setting).Save(); #endregion From 71ca3bbf38b4fd55aca0540530d812d6df9d7011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 18:15:46 +0800 Subject: [PATCH 3/6] formatting --- Flow.Launcher/PublicAPIInstance.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 967cf1bf7c8..327ee665845 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -111,8 +111,6 @@ public void OpenSettingDialog() public List GetAllPlugins() => PluginManager.AllPlugins.ToList(); - public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; - public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); public Task HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url); @@ -125,7 +123,6 @@ public void OpenSettingDialog() 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 LogInfo(string className, string message, [CallerMemberName] string methodName = "") => Log.Info(className, message, methodName); @@ -138,6 +135,7 @@ public void OpenSettingDialog() public void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new() => new PluginJsonStorage(setting).Save(); + public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; #endregion From 8a26471c4fca63ce8b413d69ce3f32fd1849f389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 18:25:09 +0800 Subject: [PATCH 4/6] Update Document and remove unused parameter --- Flow.Launcher.Plugin/IPublicAPI.cs | 61 +++++++++++++++++++++++++++++- Flow.Launcher/PublicAPIInstance.cs | 4 +- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 2a69a2495ce..a3f711a175c 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -89,28 +89,85 @@ public interface IPublicAPI /// event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; + /// + /// Fuzzy Search the string with query + /// + /// Query String + /// The string to Search for Query + /// Match results MatchResult FuzzySearch(string query, string stringToCompare); + /// + /// Http Get to the spefic URL + /// + /// URL to call Http Get + /// Cancellation Token + /// Task to get string result Task HttpGetStringAsync(string url, CancellationToken token = default); + /// + /// Http Get to the spefic URL + /// + /// URL to call Http Get + /// Cancellation Token + /// Task to get stream result Task HttpGetStreamAsync(string url, CancellationToken token = default); + /// + /// Download the specific url to a cretain file path + /// + /// URL to download file + /// place to store file + /// Task showing the progress Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath); + /// + /// Add ActionKeyword for specific plugin + /// + /// ID for plugin that needs to add action keyword + /// The actionkeyword that is supposed to be added void AddActionKeyword(string pluginId, string newActionKeyword); + /// + /// Remove ActionKeyword for specific plugin + /// + /// ID for plugin that needs to remove action keyword + /// The actionkeyword that is supposed to be removed void RemoveActionKeyword(string pluginId, string oldActionKeyword); + /// + /// Log Debug message + /// Message will only be logged in Debug mode + /// void LogDebug(string className, string message, [CallerMemberName] string methodName = ""); + /// + /// Log Message + /// void LogInfo(string className, string message, [CallerMemberName] string methodName = ""); + /// + /// Log Warning + /// void LogWarn(string className, string message, [CallerMemberName] string methodName = ""); + /// + /// Log an Exception + /// void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = ""); - T LoadJsonStorage(PluginMetadata metadata) where T : new(); + /// + /// Load JsonStorage for current plugin + /// + /// Type for deserialization + /// + T LoadJsonStorage() where T : new(); - void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new(); + /// + /// Save JsonStorage for current plugin + /// + /// Type for Serialization + /// + void SaveJsonStorage(T setting) where T : new(); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 327ee665845..200eb166a11 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -131,9 +131,9 @@ public void OpenSettingDialog() 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() => new PluginJsonStorage().Load(); + public T LoadJsonStorage() where T : new() => new PluginJsonStorage().Load(); - public void SaveJsonStorage(PluginMetadata metadata, T setting) where T : new() => new PluginJsonStorage(setting).Save(); + public void SaveJsonStorage(T setting) where T : new() => new PluginJsonStorage(setting).Save(); public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; From 20c0b1788ffda2c5ac38589f828912cb5bc80137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 22:43:11 +0800 Subject: [PATCH 5/6] Add Cancellation to IPublicAPI download method --- Flow.Launcher.Plugin/IPublicAPI.cs | 2 +- Flow.Launcher/PublicAPIInstance.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index a3f711a175c..27a65191a0e 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -119,7 +119,7 @@ public interface IPublicAPI /// URL to download file /// place to store file /// Task showing the progress - Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath); + Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default); /// /// Add ActionKeyword for specific plugin diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 200eb166a11..6c55e37fe04 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -117,7 +117,7 @@ public void OpenSettingDialog() public Task HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url); - public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath) => Http.DownloadAsync(url, filePath); + 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); From 14e51c07310fd38d5e0a93964bf04a4c77ab9695 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 15 Feb 2021 06:42:18 +1100 Subject: [PATCH 6/6] update comments --- Flow.Launcher.Plugin/IPublicAPI.cs | 23 ++++++++++++----------- Flow.Launcher/PublicAPIInstance.cs | 1 - 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 27a65191a0e..07e2b270053 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -90,15 +90,15 @@ public interface IPublicAPI event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; /// - /// Fuzzy Search the string with query + /// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses /// - /// Query String - /// The string to Search for Query + /// Query string + /// The string that will be compared against the query /// Match results MatchResult FuzzySearch(string query, string stringToCompare); /// - /// Http Get to the spefic URL + /// Http download the spefic url and return as string /// /// URL to call Http Get /// Cancellation Token @@ -106,7 +106,7 @@ public interface IPublicAPI Task HttpGetStringAsync(string url, CancellationToken token = default); /// - /// Http Get to the spefic URL + /// Http download the spefic url and return as stream /// /// URL to call Http Get /// Cancellation Token @@ -136,35 +136,36 @@ public interface IPublicAPI void RemoveActionKeyword(string pluginId, string oldActionKeyword); /// - /// Log Debug message + /// Log debug message /// Message will only be logged in Debug mode /// void LogDebug(string className, string message, [CallerMemberName] string methodName = ""); /// - /// Log Message + /// Log info message /// void LogInfo(string className, string message, [CallerMemberName] string methodName = ""); /// - /// Log Warning + /// Log warning message /// void LogWarn(string className, string message, [CallerMemberName] string methodName = ""); /// - /// Log an Exception + /// Log an Exception. Will throw if in debug mode so developer will be aware, + /// otherwise logs the eror message. This is the primary logging method used for Flow /// void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = ""); /// - /// Load JsonStorage for current plugin + /// Load JsonStorage for current plugin. This is the method used to load settings from json in Flow /// /// Type for deserialization /// T LoadJsonStorage() where T : new(); /// - /// Save JsonStorage for current plugin + /// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow /// /// Type for Serialization /// diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 6c55e37fe04..9b41c2c05ba 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -150,7 +150,6 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe return true; } - #endregion } }