Skip to content

Commit 6abd37d

Browse files
authored
Merge pull request #969 from Flow-Launcher/windowsSettingtranslationWarning
Move Tasklink Name into Resource (except altName) & Glyph Icon Support
2 parents 1e07b6c + a550e58 commit 6abd37d

21 files changed

+4795
-2039
lines changed

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void ChangeLanguage(Language language)
9999
Settings.Language = language.LanguageCode;
100100
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
101101
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
102-
Task.Run(() =>
102+
_ = Task.Run(() =>
103103
{
104104
UpdatePluginMetadataTranslations();
105105
});
@@ -182,6 +182,7 @@ private void UpdatePluginMetadataTranslations()
182182
{
183183
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
184184
p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription();
185+
pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture);
185186
}
186187
catch (Exception e)
187188
{

Plugins/Flow.Launcher.Plugin.WindowsSettings/Classes/WindowsSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public WindowsSetting()
5757
/// <summary>
5858
/// Gets or sets the Glyph of this setting
5959
/// </summary>
60-
public string? glyph { get; set; }
60+
public GlyphInfo? IconGlyph { get; set; }
6161

6262
/// <summary>
6363
/// Gets or sets a additional note of this settings.

Plugins/Flow.Launcher.Plugin.WindowsSettings/Flow.Launcher.Plugin.WindowsSettings.csproj

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Library</OutputType>
44
<TargetFramework>net6.0-windows</TargetFramework>
@@ -32,22 +32,11 @@
3232
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3333
</PropertyGroup>
3434

35-
<ItemGroup>
36-
<None Remove="WindowsSettings.json" />
37-
</ItemGroup>
38-
3935
<ItemGroup>
4036
<None Include="plugin.json">
4137
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4238
</None>
4339
</ItemGroup>
44-
45-
46-
<ItemGroup>
47-
<EmbeddedResource Include="WindowsSettings.json">
48-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
49-
</EmbeddedResource>
50-
</ItemGroup>
5140

5241
<ItemGroup>
5342
<Compile Update="Properties\Resources.Designer.cs">
@@ -59,7 +48,7 @@
5948

6049
<ItemGroup>
6150
<EmbeddedResource Update="Properties\Resources.resx">
62-
<Generator>ResXFileCodeGenerator</Generator>
51+
<Generator>PublicResXFileCodeGenerator</Generator>
6352
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
6453
</EmbeddedResource>
6554
</ItemGroup>
@@ -69,6 +58,12 @@
6958
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7059
</Content>
7160
</ItemGroup>
61+
62+
63+
<ItemGroup>
64+
<EmbeddedResource Include="WindowsSettings.json">
65+
</EmbeddedResource>
66+
</ItemGroup>
7267
<ItemGroup>
7368
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
7469
</ItemGroup>

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

Lines changed: 36 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,24 @@ 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+
Glyph = entry.IconGlyph,
120+
SubTitle = GetSubtitle(entry.Area, type),
121+
Title = entry.Name,
122+
ContextData = entry,
123+
Score = score - (type == "TaskLink" ? TaskLinkScorePanelty : 0),
124+
};
125+
104126
private static string GetSubtitle(string section, string entryType)
105127
{
106128
var settingType = entryType == "AppSettingsApp" ? "System settings" : "Control Panel";

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
3+
using System.Globalization;
34
using System.Linq;
45
using Flow.Launcher.Plugin.WindowsSettings.Classes;
56
using Flow.Launcher.Plugin.WindowsSettings.Properties;
@@ -40,18 +41,14 @@ internal static IEnumerable<WindowsSetting> TranslateAllSettings(in IEnumerable<
4041

4142
if (string.IsNullOrEmpty(type))
4243
{
43-
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(Main));
44+
Log.Warn($"Resource string for [{settings.Type}] not found", typeof(Main));
4445
}
4546

4647

4748

4849
if (!string.IsNullOrEmpty(settings.Note))
4950
{
5051
var note = Resources.ResourceManager.GetString(settings.Note);
51-
if (string.IsNullOrEmpty(note))
52-
{
53-
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(Main));
54-
}
5552

5653
settings.Note = note ?? settings.Note ?? string.Empty;
5754
}
@@ -67,10 +64,6 @@ internal static IEnumerable<WindowsSetting> TranslateAllSettings(in IEnumerable<
6764
}
6865

6966
var translatedAltName = Resources.ResourceManager.GetString(altName);
70-
if (string.IsNullOrEmpty(translatedAltName))
71-
{
72-
Log.Warn($"Resource string for [{altName}] not found", typeof(Main));
73-
}
7467

7568
translatedAltNames.Add(translatedAltName ?? altName);
7669
}

0 commit comments

Comments
 (0)