From b67f5de4c57f5a7ce3a2bdb1d9cd283a8665e411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sat, 5 Dec 2020 16:55:06 +0800 Subject: [PATCH 1/7] Port StringMatcher.FuzzySearch to IPublicAPI --- Flow.Launcher.Plugin/IPublicAPI.cs | 2 ++ Flow.Launcher/PublicAPIInstance.cs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 68197390509..b6f3f068031 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -88,5 +88,7 @@ public interface IPublicAPI /// if you want to hook something like Ctrl+R, you should use this event /// event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; + + public (List MatchedData, int Score, bool Success) MatchString(string query, string stringToCompare); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 0cc5a0e5d1f..5d1ea7f24a5 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -132,6 +132,12 @@ public List GetAllPlugins() public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; + public (List MatchedData, int Score, bool Success) MatchString(string query, string stringToCompare) + { + var result = StringMatcher.FuzzySearch(query, stringToCompare); + return (result.MatchData, result.Score, result.Success); + } + #endregion #region Private Methods @@ -144,6 +150,7 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe } return true; } + #endregion } } From a8e4c504d066a36498e7cbeb33f14797ac3e35f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 8 Jan 2021 15:52:45 +0800 Subject: [PATCH 2/7] Move MatchResult to Flow.Launcher.Plugin so that plugins can utilize main method --- Flow.Launcher.Infrastructure/StringMatcher.cs | 69 +---------------- .../UserSettings/Settings.cs | 11 +-- .../Flow.Launcher.Plugin.csproj | 2 +- Flow.Launcher.Plugin/IPublicAPI.cs | 5 +- .../SharedModel/MatchResult.cs | 74 ++++++++++++++++++ Flow.Launcher.Test/FuzzyMatcherTest.cs | 75 ++++++++++--------- Flow.Launcher/PublicAPIInstance.cs | 7 +- .../ViewModel/SettingWindowViewModel.cs | 3 +- .../Commands/Bookmarks.cs | 1 + 9 files changed, 129 insertions(+), 118 deletions(-) create mode 100644 Flow.Launcher.Plugin/SharedModel/MatchResult.cs diff --git a/Flow.Launcher.Infrastructure/StringMatcher.cs b/Flow.Launcher.Infrastructure/StringMatcher.cs index 2a4270fb4b2..300404b9e9b 100644 --- a/Flow.Launcher.Infrastructure/StringMatcher.cs +++ b/Flow.Launcher.Infrastructure/StringMatcher.cs @@ -1,3 +1,4 @@ +using Flow.Launcher.Plugin.SharedModel; using System; using System.Collections.Generic; using System.ComponentModel; @@ -239,75 +240,9 @@ private static int CalculateSearchScore(string query, string stringToCompare, in return score; } - - public enum SearchPrecisionScore - { - Regular = 50, - Low = 20, - None = 0 - } } - public class MatchResult - { - public MatchResult(bool success, SearchPrecisionScore searchPrecision) - { - Success = success; - SearchPrecision = searchPrecision; - } - - public MatchResult(bool success, SearchPrecisionScore searchPrecision, List matchData, int rawScore) - { - Success = success; - SearchPrecision = searchPrecision; - MatchData = matchData; - RawScore = rawScore; - } - - public bool Success { get; set; } - - /// - /// The final score of the match result with search precision filters applied. - /// - public int Score { get; private set; } - - /// - /// The raw calculated search score without any search precision filtering applied. - /// - private int _rawScore; - - public int RawScore - { - get { return _rawScore; } - set - { - _rawScore = value; - Score = ScoreAfterSearchPrecisionFilter(_rawScore); - } - } - - /// - /// Matched data to highlight. - /// - public List MatchData { get; set; } - - public SearchPrecisionScore SearchPrecision { get; set; } - - public bool IsSearchPrecisionScoreMet() - { - return IsSearchPrecisionScoreMet(_rawScore); - } - - private bool IsSearchPrecisionScoreMet(int rawScore) - { - return rawScore >= (int)SearchPrecision; - } - - private int ScoreAfterSearchPrecisionFilter(int rawScore) - { - return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0; - } - } + public class MatchOption { diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 837fe3b7164..891ce792400 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Flow.Launcher.Plugin; +using Flow.Launcher.Plugin.SharedModel; namespace Flow.Launcher.Infrastructure.UserSettings { @@ -30,7 +31,7 @@ public class Settings : BaseModel /// public bool ShouldUsePinyin { get; set; } = false; - internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular; + internal SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular; [JsonIgnore] public string QuerySearchPrecisionString @@ -40,8 +41,8 @@ public string QuerySearchPrecisionString { try { - var precisionScore = (StringMatcher.SearchPrecisionScore)Enum - .Parse(typeof(StringMatcher.SearchPrecisionScore), value); + var precisionScore = (SearchPrecisionScore)Enum + .Parse(typeof(SearchPrecisionScore), value); QuerySearchPrecision = precisionScore; StringMatcher.Instance.UserSettingSearchPrecision = precisionScore; @@ -50,8 +51,8 @@ public string QuerySearchPrecisionString { Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e); - QuerySearchPrecision = StringMatcher.SearchPrecisionScore.Regular; - StringMatcher.Instance.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular; + QuerySearchPrecision = SearchPrecisionScore.Regular; + StringMatcher.Instance.UserSettingSearchPrecision = SearchPrecisionScore.Regular; throw; } diff --git a/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj b/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj index 0f6450d1899..cefbfb1c8e3 100644 --- a/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj +++ b/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index b6f3f068031..ae554044e71 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -1,4 +1,5 @@ -using System; +using Flow.Launcher.Plugin.SharedModel; +using System; using System.Collections.Generic; namespace Flow.Launcher.Plugin @@ -89,6 +90,6 @@ public interface IPublicAPI /// event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; - public (List MatchedData, int Score, bool Success) MatchString(string query, string stringToCompare); + public MatchResult FuzzySearch(string query, string stringToCompare); } } diff --git a/Flow.Launcher.Plugin/SharedModel/MatchResult.cs b/Flow.Launcher.Plugin/SharedModel/MatchResult.cs new file mode 100644 index 00000000000..26fc09cb9a8 --- /dev/null +++ b/Flow.Launcher.Plugin/SharedModel/MatchResult.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Flow.Launcher.Plugin.SharedModel +{ + public class MatchResult + { + public MatchResult(bool success, SearchPrecisionScore searchPrecision) + { + Success = success; + SearchPrecision = searchPrecision; + } + + public MatchResult(bool success, SearchPrecisionScore searchPrecision, List matchData, int rawScore) + { + Success = success; + SearchPrecision = searchPrecision; + MatchData = matchData; + RawScore = rawScore; + } + + public bool Success { get; set; } + + /// + /// The final score of the match result with search precision filters applied. + /// + public int Score { get; private set; } + + /// + /// The raw calculated search score without any search precision filtering applied. + /// + private int _rawScore; + + public int RawScore + { + get { return _rawScore; } + set + { + _rawScore = value; + Score = ScoreAfterSearchPrecisionFilter(_rawScore); + } + } + + /// + /// Matched data to highlight. + /// + public List MatchData { get; set; } + + public SearchPrecisionScore SearchPrecision { get; set; } + + public bool IsSearchPrecisionScoreMet() + { + return IsSearchPrecisionScoreMet(_rawScore); + } + + private bool IsSearchPrecisionScoreMet(int rawScore) + { + return rawScore >= (int)SearchPrecision; + } + + private int ScoreAfterSearchPrecisionFilter(int rawScore) + { + return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0; + } + } + + public enum SearchPrecisionScore + { + Regular = 50, + Low = 20, + None = 0 + } +} diff --git a/Flow.Launcher.Test/FuzzyMatcherTest.cs b/Flow.Launcher.Test/FuzzyMatcherTest.cs index 468b944573e..97e5f25749d 100644 --- a/Flow.Launcher.Test/FuzzyMatcherTest.cs +++ b/Flow.Launcher.Test/FuzzyMatcherTest.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin; +using Flow.Launcher.Plugin.SharedModel; namespace Flow.Launcher.Test { @@ -37,8 +38,8 @@ public List GetPrecisionScores() { var listToReturn = new List(); - Enum.GetValues(typeof(StringMatcher.SearchPrecisionScore)) - .Cast() + Enum.GetValues(typeof(SearchPrecisionScore)) + .Cast() .ToList() .ForEach(x => listToReturn.Add((int)x)); @@ -145,20 +146,20 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring( $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}"); } - [TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("chr", "Google Chrome", StringMatcher.SearchPrecisionScore.Low, true)] - [TestCase("chr", "Chrome", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Low, true)] - [TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.None, true)] - [TestCase("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Low, true)] - [TestCase("cand", "Candy Crush Saga from King",StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)] + [TestCase("goo", "Google Chrome", SearchPrecisionScore.Regular, true)] + [TestCase("chr", "Google Chrome", SearchPrecisionScore.Low, true)] + [TestCase("chr", "Chrome", SearchPrecisionScore.Regular, true)] + [TestCase("chr", "Help cure hope raise on mind entity Chrome", SearchPrecisionScore.Regular, false)] + [TestCase("chr", "Help cure hope raise on mind entity Chrome", SearchPrecisionScore.Low, true)] + [TestCase("chr", "Candy Crush Saga from King", SearchPrecisionScore.Regular, false)] + [TestCase("chr", "Candy Crush Saga from King", SearchPrecisionScore.None, true)] + [TestCase("ccs", "Candy Crush Saga from King", SearchPrecisionScore.Low, true)] + [TestCase("cand", "Candy Crush Saga from King",SearchPrecisionScore.Regular, true)] + [TestCase("cand", "Help cure hope raise on mind entity Chrome", SearchPrecisionScore.Regular, false)] public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual( string queryString, string compareString, - StringMatcher.SearchPrecisionScore expectedPrecisionScore, + SearchPrecisionScore expectedPrecisionScore, bool expectedPrecisionResult) { // When @@ -182,32 +183,32 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual( $"Precision Score: {(int)expectedPrecisionScore}"); } - [TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("term", "Windows Terminal (Preview)", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("sql s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("sql manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("sql", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("sql serv", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("servez", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("sql servz", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("sql serv man", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("sql studio", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("mic", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("chr", "Shutdown", StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("mssms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, false)] - [TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("cod", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("code", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)] - [TestCase("codes", "Visual Studio Codes", StringMatcher.SearchPrecisionScore.Regular, true)] + [TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", SearchPrecisionScore.Regular, false)] + [TestCase("term", "Windows Terminal (Preview)", SearchPrecisionScore.Regular, true)] + [TestCase("sql s managa", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, false)] + [TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, false)] + [TestCase("sql s manag", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("sql manag", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("sql", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("sql serv", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("servez", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, false)] + [TestCase("sql servz", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, false)] + [TestCase("sql serv man", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("sql studio", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("mic", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, true)] + [TestCase("chr", "Shutdown", SearchPrecisionScore.Regular, false)] + [TestCase("mssms", MicrosoftSqlServerManagementStudio, SearchPrecisionScore.Regular, false)] + [TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", SearchPrecisionScore.Regular, false)] + [TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", SearchPrecisionScore.Regular, true)] + [TestCase("a test", "This is a test", SearchPrecisionScore.Regular, true)] + [TestCase("test", "This is a test", SearchPrecisionScore.Regular, true)] + [TestCase("cod", VisualStudioCode, SearchPrecisionScore.Regular, true)] + [TestCase("code", VisualStudioCode, SearchPrecisionScore.Regular, true)] + [TestCase("codes", "Visual Studio Codes", SearchPrecisionScore.Regular, true)] public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings( string queryString, string compareString, - StringMatcher.SearchPrecisionScore expectedPrecisionScore, + SearchPrecisionScore expectedPrecisionScore, bool expectedPrecisionResult) { // When @@ -238,7 +239,7 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord( string queryString, string compareString1, string compareString2) { // When - var matcher = new StringMatcher { UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular }; + var matcher = new StringMatcher { UserSettingSearchPrecision = SearchPrecisionScore.Regular }; // Given var compareString1Result = matcher.FuzzyMatch(queryString, compareString1); diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 5d1ea7f24a5..9cf3b0f4e90 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -14,6 +14,7 @@ using Flow.Launcher.Infrastructure.Image; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; +using Flow.Launcher.Plugin.SharedModel; namespace Flow.Launcher { @@ -132,11 +133,7 @@ public List GetAllPlugins() public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; - public (List MatchedData, int Score, bool Success) MatchString(string query, string stringToCompare) - { - var result = StringMatcher.FuzzySearch(query, stringToCompare); - return (result.MatchData, result.Score, result.Success); - } + public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); #endregion diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 853925852a1..5eec3962a56 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -17,6 +17,7 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.Plugin.SharedModel; namespace Flow.Launcher.ViewModel { @@ -152,7 +153,7 @@ public List QuerySearchPrecisionStrings { var precisionStrings = new List(); - var enumList = Enum.GetValues(typeof(StringMatcher.SearchPrecisionScore)).Cast().ToList(); + var enumList = Enum.GetValues(typeof(SearchPrecisionScore)).Cast().ToList(); enumList.ForEach(x => precisionStrings.Add(x.ToString())); diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs index c7013aa677b..4e3f4f513cf 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Flow.Launcher.Infrastructure; +using Flow.Launcher.Plugin.SharedModel; namespace Flow.Launcher.Plugin.BrowserBookmark.Commands { From 4f35e621616baf5477e853d186c503e6a3cbc69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 8 Jan 2021 16:00:06 +0800 Subject: [PATCH 3/7] Add Http.Get and Http.GetAsync to IPublicAPI --- Flow.Launcher.Plugin/IPublicAPI.cs | 9 ++++++++- Flow.Launcher/PublicAPIInstance.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index ae554044e71..147741ba8e0 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -1,6 +1,9 @@ using Flow.Launcher.Plugin.SharedModel; using System; using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; namespace Flow.Launcher.Plugin { @@ -90,6 +93,10 @@ public interface IPublicAPI /// event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; - public MatchResult FuzzySearch(string query, string stringToCompare); + MatchResult FuzzySearch(string query, string stringToCompare); + + Task HttpGetStringAsync(string url, CancellationToken token = default); + + Task HttpGetStreamAsync(string url, CancellationToken token = default); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 9cf3b0f4e90..6f6a4a01192 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -15,6 +15,8 @@ using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; using Flow.Launcher.Plugin.SharedModel; +using System.Threading; +using System.IO; namespace Flow.Launcher { @@ -135,6 +137,16 @@ public List GetAllPlugins() public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); + public Task HttpGetStringAsync(string url, CancellationToken token = default) + { + return null; + } + + public Task HttpGetStreamAsync(string url, CancellationToken token = default) + { + return null; + } + #endregion #region Private Methods From a3975a353167a2e63426be2d11abb74dd088f05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 8 Jan 2021 16:01:39 +0800 Subject: [PATCH 4/7] implement the Http method in publicapiinstance --- Flow.Launcher/PublicAPIInstance.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index e0b9c153fec..e214d73e732 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -17,6 +17,7 @@ using Flow.Launcher.Plugin.SharedModel; using System.Threading; using System.IO; +using Flow.Launcher.Infrastructure.Http; namespace Flow.Launcher { @@ -134,12 +135,12 @@ public List GetAllPlugins() public Task HttpGetStringAsync(string url, CancellationToken token = default) { - return null; + return Http.GetAsync(url); } public Task HttpGetStreamAsync(string url, CancellationToken token = default) { - return null; + return Http.GetStreamAsync(url); } #endregion From bd74a87d0880891473b5df617a3c7e92dc75451e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 8 Jan 2021 16:05:50 +0800 Subject: [PATCH 5/7] add Http.DownloadAsync --- Flow.Launcher.Plugin/IPublicAPI.cs | 3 +++ Flow.Launcher/PublicAPIInstance.cs | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 9083b2d7464..4c89973ae09 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -1,4 +1,5 @@ using Flow.Launcher.Plugin.SharedModel; +using JetBrains.Annotations; using System; using System.Collections.Generic; using System.IO; @@ -92,5 +93,7 @@ public interface IPublicAPI Task HttpGetStringAsync(string url, CancellationToken token = default); Task HttpGetStreamAsync(string url, CancellationToken token = default); + + Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index e214d73e732..809a4b92006 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -18,6 +18,7 @@ using System.Threading; using System.IO; using Flow.Launcher.Infrastructure.Http; +using JetBrains.Annotations; namespace Flow.Launcher { @@ -96,7 +97,7 @@ public void ShowMsg(string title, string subTitle, string iconPath, bool useMain { Application.Current.Dispatcher.Invoke(() => { - var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg(); + var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg(); msg.Show(title, subTitle, iconPath); }); } @@ -143,6 +144,11 @@ public Task HttpGetStreamAsync(string url, CancellationToken token = def return Http.GetStreamAsync(url); } + public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath) + { + return Http.DownloadAsync(url, filePath); + } + #endregion #region Private Methods From 4f5b2d35e8eb69aae37741a22e725b00d00e5135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 8 Jan 2021 16:08:39 +0800 Subject: [PATCH 6/7] Allow plugin to add & remove actionkeywords --- Flow.Launcher.Plugin/IPublicAPI.cs | 5 +++++ Flow.Launcher/PublicAPIInstance.cs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 4c89973ae09..b28abbfcc1d 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -95,5 +95,10 @@ public interface IPublicAPI Task HttpGetStreamAsync(string url, CancellationToken token = default); Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath); + + void AddActionKeyword(string pluginId, string newActionKeyword); + + void RemoveActionKeyword(string pluginId, string oldActionKeyword); + } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 809a4b92006..5c892c5575f 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -149,6 +149,15 @@ public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath) return Http.DownloadAsync(url, filePath); } + public void AddActionKeyword(string pluginId, string newActionKeyword) + { + PluginManager.AddActionKeyword(pluginId, newActionKeyword); + } + + public void RemoveActionKeyword(string pluginId, string oldActionKeyword) + { + PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword); + } #endregion #region Private Methods From e31bef7d3c7481a45f63427308efa1132b06fee6 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 26 Jan 2021 18:01:39 +1100 Subject: [PATCH 7/7] fix formatting + naming --- Flow.Launcher.Infrastructure/StringMatcher.cs | 6 +----- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 2 +- Flow.Launcher.Plugin/IPublicAPI.cs | 2 +- .../{SharedModel => SharedModels}/MatchResult.cs | 6 ++---- Flow.Launcher.Test/FuzzyMatcherTest.cs | 2 +- Flow.Launcher/PublicAPIInstance.cs | 3 +-- Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 2 +- .../Commands/Bookmarks.cs | 2 +- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 1 - 9 files changed, 9 insertions(+), 17 deletions(-) rename Flow.Launcher.Plugin/{SharedModel => SharedModels}/MatchResult.cs (94%) diff --git a/Flow.Launcher.Infrastructure/StringMatcher.cs b/Flow.Launcher.Infrastructure/StringMatcher.cs index 300404b9e9b..bc4e4b408df 100644 --- a/Flow.Launcher.Infrastructure/StringMatcher.cs +++ b/Flow.Launcher.Infrastructure/StringMatcher.cs @@ -1,9 +1,7 @@ -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; -using static Flow.Launcher.Infrastructure.StringMatcher; namespace Flow.Launcher.Infrastructure { @@ -242,8 +240,6 @@ private static int CalculateSearchScore(string query, string stringToCompare, in } } - - public class MatchOption { public bool IgnoreCase { get; set; } = true; diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 5a6bd0a2f59..76a370978bd 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -3,7 +3,7 @@ using System.Drawing; using System.Text.Json.Serialization; using Flow.Launcher.Plugin; -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.Infrastructure.UserSettings { diff --git a/Flow.Launcher.Plugin/IPublicAPI.cs b/Flow.Launcher.Plugin/IPublicAPI.cs index 3bc2f8e63f5..dd73eb0e523 100644 --- a/Flow.Launcher.Plugin/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/IPublicAPI.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; using JetBrains.Annotations; using System; using System.Collections.Generic; diff --git a/Flow.Launcher.Plugin/SharedModel/MatchResult.cs b/Flow.Launcher.Plugin/SharedModels/MatchResult.cs similarity index 94% rename from Flow.Launcher.Plugin/SharedModel/MatchResult.cs rename to Flow.Launcher.Plugin/SharedModels/MatchResult.cs index 26fc09cb9a8..5144eb61d66 100644 --- a/Flow.Launcher.Plugin/SharedModel/MatchResult.cs +++ b/Flow.Launcher.Plugin/SharedModels/MatchResult.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; -namespace Flow.Launcher.Plugin.SharedModel +namespace Flow.Launcher.Plugin.SharedModels { public class MatchResult { diff --git a/Flow.Launcher.Test/FuzzyMatcherTest.cs b/Flow.Launcher.Test/FuzzyMatcherTest.cs index 97e5f25749d..14a0fd92a05 100644 --- a/Flow.Launcher.Test/FuzzyMatcherTest.cs +++ b/Flow.Launcher.Test/FuzzyMatcherTest.cs @@ -5,7 +5,7 @@ using NUnit.Framework; using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin; -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.Test { diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 0a824ee81fa..427fd9fc639 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using System.Windows; using Squirrel; -using Flow.Launcher.Core; using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; @@ -14,7 +13,7 @@ using Flow.Launcher.Infrastructure.Image; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; using System.Threading; using System.IO; using Flow.Launcher.Infrastructure.Http; diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index f4a34e754f5..98685dc1b72 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -17,7 +17,7 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.ViewModel { diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs index 4e3f4f513cf..60c4a0ee660 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Flow.Launcher.Infrastructure; -using Flow.Launcher.Plugin.SharedModel; +using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.Plugin.BrowserBookmark.Commands { diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 624fe05bc80..0aa37cdf583 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; -using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Interop;