Skip to content

Commit 123cad8

Browse files
committed
adjust default result when query is empty
Make Tasklink Area Unknown Make Tasklink results score lower
1 parent b2090bc commit 123cad8

File tree

4 files changed

+301
-268
lines changed

4 files changed

+301
-268
lines changed

Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ internal static class ResultHelper
1818

1919
public static void Init(IPublicAPI api) => _api = api;
2020

21+
private static List<Result> GetDefaultReuslts(in IEnumerable<WindowsSetting> list,
22+
string windowsSettingIconPath,
23+
string controlPanelIconPath)
24+
{
25+
return list.Select(entry =>
26+
{
27+
var result = NewSettingResult(100, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
28+
AddOptionalToolTip(entry, result);
29+
return result;
30+
}).ToList();
31+
}
32+
2133
/// <summary>
2234
/// Return a list with <see cref="Result"/>s, based on the given list.
2335
/// </summary>
@@ -31,21 +43,28 @@ internal static List<Result> GetResultList(
3143
string windowsSettingIconPath,
3244
string controlPanelIconPath)
3345
{
46+
if (string.IsNullOrWhiteSpace(query.Search))
47+
{
48+
return GetDefaultReuslts(list, windowsSettingIconPath, controlPanelIconPath);
49+
}
50+
3451
var resultList = new List<Result>();
52+
3553
foreach (var entry in list)
3654
{
3755
// Adjust the score to lower the order of many irrelevant matches from area strings
3856
// that may only be for description.
3957
const int nonNameMatchScoreAdj = 10;
4058

59+
4160
Result? result;
4261
Debug.Assert(_api != null, nameof(_api) + " != null");
4362

4463
var nameMatch = _api.FuzzySearch(query.Search, entry.Name);
4564

4665
if (nameMatch.IsSearchPrecisionScoreMet())
4766
{
48-
var settingResult = NewSettingResult(nameMatch.Score, entry.Type);
67+
var settingResult = NewSettingResult(nameMatch.Score, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
4968
settingResult.TitleHighlightData = nameMatch.MatchData;
5069
result = settingResult;
5170
}
@@ -54,15 +73,15 @@ internal static List<Result> GetResultList(
5473
var areaMatch = _api.FuzzySearch(query.Search, entry.Area);
5574
if (areaMatch.IsSearchPrecisionScoreMet())
5675
{
57-
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type);
76+
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
5877
result = settingResult;
5978
}
6079
else
6180
{
6281
result = entry.AltNames?
6382
.Select(altName => _api.FuzzySearch(query.Search, altName))
6483
.Where(match => match.IsSearchPrecisionScoreMet())
65-
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type))
84+
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry))
6685
.FirstOrDefault();
6786
}
6887

@@ -76,7 +95,7 @@ internal static List<Result> GetResultList(
7695
.SelectMany(x => x)
7796
.Contains(x, StringComparer.CurrentCultureIgnoreCase))
7897
)
79-
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type);
98+
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
8099
}
81100
}
82101

@@ -86,21 +105,23 @@ internal static List<Result> GetResultList(
86105
AddOptionalToolTip(entry, result);
87106

88107
resultList.Add(result);
89-
90-
Result NewSettingResult(int score, string type) => new()
91-
{
92-
Action = _ => DoOpenSettingsAction(entry),
93-
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
94-
SubTitle = GetSubtitle(entry.Area, type),
95-
Title = entry.Name + entry.glyph,
96-
ContextData = entry,
97-
Score = score
98-
};
99108
}
100109

101110
return resultList;
102111
}
103112

113+
private const int TaskLinkScorePanelty = 50;
114+
115+
private static Result NewSettingResult(int score, string type, string windowsSettingIconPath, string controlPanelIconPath, WindowsSetting entry) => new()
116+
{
117+
Action = _ => DoOpenSettingsAction(entry),
118+
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
119+
SubTitle = GetSubtitle(entry.Area, type),
120+
Title = entry.Name + entry.glyph,
121+
ContextData = entry,
122+
Score = score - (type == "TaskLink" ? TaskLinkScorePanelty : 0),
123+
};
124+
104125
private static string GetSubtitle(string section, string entryType)
105126
{
106127
var settingType = entryType == "AppSettingsApp" ? "System settings" : "Control Panel";

Plugins/Flow.Launcher.Plugin.WindowsSettings/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/Flow.Launcher.Plugin.WindowsSettings/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,4 +2508,7 @@
25082508
<data name="TaskLink" xml:space="preserve">
25092509
<value>TaskLink</value>
25102510
</data>
2511+
<data name="AreaUnknown" xml:space="preserve">
2512+
<value>Unknown</value>
2513+
</data>
25112514
</root>

0 commit comments

Comments
 (0)