Skip to content

Commit 67b0bfd

Browse files
committed
Merge dev
2 parents 597dc06 + d3127b7 commit 67b0bfd

File tree

10 files changed

+138
-84
lines changed

10 files changed

+138
-84
lines changed

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
using Flow.Launcher.Plugin.SharedModels;
12
using System;
23
using System.Collections.Generic;
3-
using System.ComponentModel;
44
using System.Linq;
5-
using static Flow.Launcher.Infrastructure.StringMatcher;
65

76
namespace Flow.Launcher.Infrastructure
87
{
@@ -310,74 +309,6 @@ private static int CalculateSearchScore(string query, string stringToCompare, in
310309

311310
return score;
312311
}
313-
314-
public enum SearchPrecisionScore
315-
{
316-
Regular = 50,
317-
Low = 20,
318-
None = 0
319-
}
320-
}
321-
322-
public class MatchResult
323-
{
324-
public MatchResult(bool success, SearchPrecisionScore searchPrecision)
325-
{
326-
Success = success;
327-
SearchPrecision = searchPrecision;
328-
}
329-
330-
public MatchResult(bool success, SearchPrecisionScore searchPrecision, List<int> matchData, int rawScore)
331-
{
332-
Success = success;
333-
SearchPrecision = searchPrecision;
334-
MatchData = matchData;
335-
RawScore = rawScore;
336-
}
337-
338-
public bool Success { get; set; }
339-
340-
/// <summary>
341-
/// The final score of the match result with search precision filters applied.
342-
/// </summary>
343-
public int Score { get; private set; }
344-
345-
/// <summary>
346-
/// The raw calculated search score without any search precision filtering applied.
347-
/// </summary>
348-
private int _rawScore;
349-
350-
public int RawScore
351-
{
352-
get { return _rawScore; }
353-
set
354-
{
355-
_rawScore = value;
356-
Score = ScoreAfterSearchPrecisionFilter(_rawScore);
357-
}
358-
}
359-
360-
/// <summary>
361-
/// Matched data to highlight.
362-
/// </summary>
363-
public List<int> MatchData { get; set; }
364-
365-
public SearchPrecisionScore SearchPrecision { get; set; }
366-
367-
public bool IsSearchPrecisionScoreMet()
368-
{
369-
return IsSearchPrecisionScoreMet(_rawScore);
370-
}
371-
372-
private bool IsSearchPrecisionScoreMet(int rawScore)
373-
{
374-
return rawScore >= (int) SearchPrecision;
375-
}
376-
377-
private int ScoreAfterSearchPrecisionFilter(int rawScore)
378-
{
379-
return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0;
380-
}
381312
}
382313

383314
public class MatchOption

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Text.Json.Serialization;
55
using Flow.Launcher.Plugin;
6+
using Flow.Launcher.Plugin.SharedModels;
67

78
namespace Flow.Launcher.Infrastructure.UserSettings
89
{
@@ -38,7 +39,7 @@ public string Language
3839
/// </summary>
3940
public bool ShouldUsePinyin { get; set; } = false;
4041

41-
internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular;
42+
internal SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular;
4243

4344
[JsonIgnore]
4445
public string QuerySearchPrecisionString
@@ -48,8 +49,8 @@ public string QuerySearchPrecisionString
4849
{
4950
try
5051
{
51-
var precisionScore = (StringMatcher.SearchPrecisionScore)Enum
52-
.Parse(typeof(StringMatcher.SearchPrecisionScore), value);
52+
var precisionScore = (SearchPrecisionScore)Enum
53+
.Parse(typeof(SearchPrecisionScore), value);
5354

5455
QuerySearchPrecision = precisionScore;
5556
StringMatcher.Instance.UserSettingSearchPrecision = precisionScore;
@@ -58,8 +59,8 @@ public string QuerySearchPrecisionString
5859
{
5960
Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e);
6061

61-
QuerySearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
62-
StringMatcher.Instance.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
62+
QuerySearchPrecision = SearchPrecisionScore.Regular;
63+
StringMatcher.Instance.UserSettingSearchPrecision = SearchPrecisionScore.Regular;
6364

6465
throw;
6566
}

Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>

Flow.Launcher.Plugin/IPublicAPI.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
using System;
1+
using Flow.Launcher.Plugin.SharedModels;
2+
using JetBrains.Annotations;
3+
using System;
24
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Threading;
37
using System.Threading.Tasks;
48

59
namespace Flow.Launcher.Plugin
@@ -83,5 +87,18 @@ public interface IPublicAPI
8387
/// if you want to hook something like Ctrl+R, you should use this event
8488
/// </summary>
8589
event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
90+
91+
MatchResult FuzzySearch(string query, string stringToCompare);
92+
93+
Task<string> HttpGetStringAsync(string url, CancellationToken token = default);
94+
95+
Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default);
96+
97+
Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath);
98+
99+
void AddActionKeyword(string pluginId, string newActionKeyword);
100+
101+
void RemoveActionKeyword(string pluginId, string oldActionKeyword);
102+
86103
}
87104
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.Generic;
2+
3+
namespace Flow.Launcher.Plugin.SharedModels
4+
{
5+
public class MatchResult
6+
{
7+
public MatchResult(bool success, SearchPrecisionScore searchPrecision)
8+
{
9+
Success = success;
10+
SearchPrecision = searchPrecision;
11+
}
12+
13+
public MatchResult(bool success, SearchPrecisionScore searchPrecision, List<int> matchData, int rawScore)
14+
{
15+
Success = success;
16+
SearchPrecision = searchPrecision;
17+
MatchData = matchData;
18+
RawScore = rawScore;
19+
}
20+
21+
public bool Success { get; set; }
22+
23+
/// <summary>
24+
/// The final score of the match result with search precision filters applied.
25+
/// </summary>
26+
public int Score { get; private set; }
27+
28+
/// <summary>
29+
/// The raw calculated search score without any search precision filtering applied.
30+
/// </summary>
31+
private int _rawScore;
32+
33+
public int RawScore
34+
{
35+
get { return _rawScore; }
36+
set
37+
{
38+
_rawScore = value;
39+
Score = ScoreAfterSearchPrecisionFilter(_rawScore);
40+
}
41+
}
42+
43+
/// <summary>
44+
/// Matched data to highlight.
45+
/// </summary>
46+
public List<int> MatchData { get; set; }
47+
48+
public SearchPrecisionScore SearchPrecision { get; set; }
49+
50+
public bool IsSearchPrecisionScoreMet()
51+
{
52+
return IsSearchPrecisionScoreMet(_rawScore);
53+
}
54+
55+
private bool IsSearchPrecisionScoreMet(int rawScore)
56+
{
57+
return rawScore >= (int)SearchPrecision;
58+
}
59+
60+
private int ScoreAfterSearchPrecisionFilter(int rawScore)
61+
{
62+
return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0;
63+
}
64+
}
65+
66+
public enum SearchPrecisionScore
67+
{
68+
Regular = 50,
69+
Low = 20,
70+
None = 0
71+
}
72+
}

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NUnit.Framework;
66
using Flow.Launcher.Infrastructure;
77
using Flow.Launcher.Plugin;
8+
using Flow.Launcher.Plugin.SharedModels;
89

910
namespace Flow.Launcher.Test
1011
{
@@ -37,8 +38,8 @@ public List<int> GetPrecisionScores()
3738
{
3839
var listToReturn = new List<int>();
3940

40-
Enum.GetValues(typeof(StringMatcher.SearchPrecisionScore))
41-
.Cast<StringMatcher.SearchPrecisionScore>()
41+
Enum.GetValues(typeof(SearchPrecisionScore))
42+
.Cast<SearchPrecisionScore>()
4243
.ToList()
4344
.ForEach(x => listToReturn.Add((int) x));
4445

@@ -160,7 +161,7 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
160161
public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
161162
string queryString,
162163
string compareString,
163-
StringMatcher.SearchPrecisionScore expectedPrecisionScore,
164+
SearchPrecisionScore expectedPrecisionScore,
164165
bool expectedPrecisionResult)
165166
{
166167
// When
@@ -218,7 +219,7 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
218219
public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
219220
string queryString,
220221
string compareString,
221-
StringMatcher.SearchPrecisionScore expectedPrecisionScore,
222+
SearchPrecisionScore expectedPrecisionScore,
222223
bool expectedPrecisionResult)
223224
{
224225
// When

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using System.Windows;
77
using Squirrel;
8-
using Flow.Launcher.Core;
98
using Flow.Launcher.Core.Plugin;
109
using Flow.Launcher.Core.Resource;
1110
using Flow.Launcher.Helper;
@@ -14,6 +13,11 @@
1413
using Flow.Launcher.Infrastructure.Image;
1514
using Flow.Launcher.Plugin;
1615
using Flow.Launcher.ViewModel;
16+
using Flow.Launcher.Plugin.SharedModels;
17+
using System.Threading;
18+
using System.IO;
19+
using Flow.Launcher.Infrastructure.Http;
20+
using JetBrains.Annotations;
1721

1822
namespace Flow.Launcher
1923
{
@@ -127,6 +131,32 @@ public List<PluginPair> GetAllPlugins()
127131

128132
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
129133

134+
public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare);
135+
136+
public Task<string> HttpGetStringAsync(string url, CancellationToken token = default)
137+
{
138+
return Http.GetAsync(url);
139+
}
140+
141+
public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default)
142+
{
143+
return Http.GetStreamAsync(url);
144+
}
145+
146+
public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath)
147+
{
148+
return Http.DownloadAsync(url, filePath);
149+
}
150+
151+
public void AddActionKeyword(string pluginId, string newActionKeyword)
152+
{
153+
PluginManager.AddActionKeyword(pluginId, newActionKeyword);
154+
}
155+
156+
public void RemoveActionKeyword(string pluginId, string oldActionKeyword)
157+
{
158+
PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword);
159+
}
130160
#endregion
131161

132162
#region Private Methods
@@ -139,6 +169,7 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe
139169
}
140170
return true;
141171
}
172+
142173
#endregion
143174
}
144175
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Flow.Launcher.Infrastructure.Storage;
1818
using Flow.Launcher.Infrastructure.UserSettings;
1919
using Flow.Launcher.Plugin;
20+
using Flow.Launcher.Plugin.SharedModels;
2021

2122
namespace Flow.Launcher.ViewModel
2223
{
@@ -153,7 +154,7 @@ public List<string> QuerySearchPrecisionStrings
153154
{
154155
var precisionStrings = new List<string>();
155156

156-
var enumList = Enum.GetValues(typeof(StringMatcher.SearchPrecisionScore)).Cast<StringMatcher.SearchPrecisionScore>().ToList();
157+
var enumList = Enum.GetValues(typeof(SearchPrecisionScore)).Cast<SearchPrecisionScore>().ToList();
157158

158159
enumList.ForEach(x => precisionStrings.Add(x.ToString()));
159160

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using Flow.Launcher.Infrastructure;
4+
using Flow.Launcher.Plugin.SharedModels;
45

56
namespace Flow.Launcher.Plugin.BrowserBookmark.Commands
67
{

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Runtime.InteropServices;
5-
using System.Threading.Tasks;
65
using System.Windows;
76
using System.Windows.Forms;
87
using System.Windows.Interop;

0 commit comments

Comments
 (0)