Skip to content
Merged
3 changes: 2 additions & 1 deletion Flow.Launcher.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void ChangeLanguage(Language language)
Settings.Language = language.LanguageCode;
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
Task.Run(() =>
_ = Task.Run(() =>
{
UpdatePluginMetadataTranslations();
});
Expand Down Expand Up @@ -182,6 +182,7 @@ private void UpdatePluginMetadataTranslations()
{
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription();
pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public WindowsSetting()
/// <summary>
/// Gets or sets the Glyph of this setting
/// </summary>
public string? glyph { get; set; }
public GlyphInfo? IconGlyph { get; set; }

/// <summary>
/// Gets or sets a additional note of this settings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
Expand Down Expand Up @@ -32,22 +32,11 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<None Remove="WindowsSettings.json" />
</ItemGroup>

<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


<ItemGroup>
<EmbeddedResource Include="WindowsSettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

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

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Expand All @@ -69,6 +58,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>


<ItemGroup>
<EmbeddedResource Include="WindowsSettings.json">
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>
Expand Down
50 changes: 36 additions & 14 deletions Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ResultHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ internal static class ResultHelper

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

private static List<Result> GetDefaultReuslts(in IEnumerable<WindowsSetting> list,
string windowsSettingIconPath,
string controlPanelIconPath)
{
return list.Select(entry =>
{
var result = NewSettingResult(100, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
AddOptionalToolTip(entry, result);
return result;
}).ToList();
}

/// <summary>
/// Return a list with <see cref="Result"/>s, based on the given list.
/// </summary>
Expand All @@ -31,21 +43,28 @@ internal static List<Result> GetResultList(
string windowsSettingIconPath,
string controlPanelIconPath)
{
if (string.IsNullOrWhiteSpace(query.Search))
{
return GetDefaultReuslts(list, windowsSettingIconPath, controlPanelIconPath);
}

var resultList = new List<Result>();

foreach (var entry in list)
{
// Adjust the score to lower the order of many irrelevant matches from area strings
// that may only be for description.
const int nonNameMatchScoreAdj = 10;


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

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

if (nameMatch.IsSearchPrecisionScoreMet())
{
var settingResult = NewSettingResult(nameMatch.Score, entry.Type);
var settingResult = NewSettingResult(nameMatch.Score, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
settingResult.TitleHighlightData = nameMatch.MatchData;
result = settingResult;
}
Expand All @@ -54,15 +73,15 @@ internal static List<Result> GetResultList(
var areaMatch = _api.FuzzySearch(query.Search, entry.Area);
if (areaMatch.IsSearchPrecisionScoreMet())
{
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type);
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
result = settingResult;
}
else
{
result = entry.AltNames?
.Select(altName => _api.FuzzySearch(query.Search, altName))
.Where(match => match.IsSearchPrecisionScoreMet())
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type))
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry))
.FirstOrDefault();
}

Expand All @@ -76,7 +95,7 @@ internal static List<Result> GetResultList(
.SelectMany(x => x)
.Contains(x, StringComparer.CurrentCultureIgnoreCase))
)
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type);
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
}
}

Expand All @@ -86,21 +105,24 @@ internal static List<Result> GetResultList(
AddOptionalToolTip(entry, result);

resultList.Add(result);

Result NewSettingResult(int score, string type) => new()
{
Action = _ => DoOpenSettingsAction(entry),
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
SubTitle = GetSubtitle(entry.Area, type),
Title = entry.Name + entry.glyph,
ContextData = entry,
Score = score
};
}

return resultList;
}

private const int TaskLinkScorePanelty = 50;

private static Result NewSettingResult(int score, string type, string windowsSettingIconPath, string controlPanelIconPath, WindowsSetting entry) => new()
{
Action = _ => DoOpenSettingsAction(entry),
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
Glyph = entry.IconGlyph,
SubTitle = GetSubtitle(entry.Area, type),
Title = entry.Name,
ContextData = entry,
Score = score - (type == "TaskLink" ? TaskLinkScorePanelty : 0),
};

private static string GetSubtitle(string section, string entryType)
{
var settingType = entryType == "AppSettingsApp" ? "System settings" : "Control Panel";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using Flow.Launcher.Plugin.WindowsSettings.Classes;
using Flow.Launcher.Plugin.WindowsSettings.Properties;
Expand Down Expand Up @@ -40,18 +41,14 @@ internal static IEnumerable<WindowsSetting> TranslateAllSettings(in IEnumerable<

if (string.IsNullOrEmpty(type))
{
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(Main));
Log.Warn($"Resource string for [{settings.Type}] not found", typeof(Main));
}



if (!string.IsNullOrEmpty(settings.Note))
{
var note = Resources.ResourceManager.GetString(settings.Note);
if (string.IsNullOrEmpty(note))
{
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(Main));
}

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

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

translatedAltNames.Add(translatedAltName ?? altName);
}
Expand Down
Loading