Skip to content

Commit a3ee3ec

Browse files
committed
Use Flow.Launcher.Localization to improve code quality
1 parent 479d665 commit a3ee3ec

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
2626
private const string IcoPath = "Images/calculator.png";
2727
private static readonly List<Result> EmptyResults = [];
2828

29-
internal static PluginInitContext Context { get; set; } = null!;
29+
internal static PluginInitContext Context { get; private set; } = null!;
3030

3131
private Settings _settings;
3232
private SettingsViewModel _viewModel;

Plugins/Flow.Launcher.Plugin.ProcessKiller/Flow.Launcher.Plugin.ProcessKiller.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<ErrorReport>prompt</ErrorReport>
3636
<WarningLevel>4</WarningLevel>
3737
<Prefer32Bit>false</Prefer32Bit>
38+
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
3839
</PropertyGroup>
3940

4041
<ItemGroup>
@@ -52,6 +53,7 @@
5253
</ItemGroup>
5354

5455
<ItemGroup>
56+
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
5557
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
5658
<PrivateAssets>all</PrivateAssets>
5759
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
1111
{
1212
internal static PluginInitContext Context { get; private set; }
1313

14-
internal static Settings Settings { get; private set; }
14+
private Settings _settings;
1515

1616
private readonly ProcessHelper processHelper = new();
1717

@@ -20,8 +20,8 @@ public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
2020
public void Init(PluginInitContext context)
2121
{
2222
Context = context;
23-
Settings = context.API.LoadSettingJsonStorage<Settings>();
24-
_viewModel = new SettingsViewModel(Settings);
23+
_settings = context.API.LoadSettingJsonStorage<Settings>();
24+
_viewModel = new SettingsViewModel(_settings);
2525
}
2626

2727
public List<Result> Query(Query query)
@@ -31,12 +31,12 @@ public List<Result> Query(Query query)
3131

3232
public string GetTranslatedPluginTitle()
3333
{
34-
return Context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_name");
34+
return Localize.flowlauncher_plugin_processkiller_plugin_name();
3535
}
3636

3737
public string GetTranslatedPluginDescription()
3838
{
39-
return Context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_description");
39+
return Localize.flowlauncher_plugin_processkiller_plugin_description();
4040
}
4141

4242
public List<Result> LoadContextMenus(Result result)
@@ -51,7 +51,7 @@ public List<Result> LoadContextMenus(Result result)
5151
{
5252
menuOptions.Add(new Result
5353
{
54-
Title = Context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
54+
Title = Localize.flowlauncher_plugin_processkiller_kill_instances(),
5555
SubTitle = processPath,
5656
Action = _ =>
5757
{
@@ -73,7 +73,7 @@ private List<Result> CreateResultsFromQuery(Query query)
7373
{
7474
// Get all non-system processes
7575
var allPocessList = processHelper.GetMatchingProcesses();
76-
if (!allPocessList.Any())
76+
if (allPocessList.Count == 0)
7777
{
7878
return null;
7979
}
@@ -82,9 +82,9 @@ private List<Result> CreateResultsFromQuery(Query query)
8282
var searchTerm = query.Search;
8383
var processlist = new List<ProcessResult>();
8484
var processWindowTitle =
85-
Settings.ShowWindowTitle || Settings.PutVisibleWindowProcessesTop ?
85+
_settings.ShowWindowTitle || _settings.PutVisibleWindowProcessesTop ?
8686
ProcessHelper.GetProcessesWithNonEmptyWindowTitle() :
87-
new Dictionary<int, string>();
87+
[];
8888
if (string.IsNullOrWhiteSpace(searchTerm))
8989
{
9090
foreach (var p in allPocessList)
@@ -97,8 +97,8 @@ private List<Result> CreateResultsFromQuery(Query query)
9797
// Use window title for those processes if enabled
9898
processlist.Add(new ProcessResult(
9999
p,
100-
Settings.PutVisibleWindowProcessesTop ? 200 : 0,
101-
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
100+
_settings.PutVisibleWindowProcessesTop ? 200 : 0,
101+
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
102102
null,
103103
progressNameIdTitle));
104104
}
@@ -129,14 +129,14 @@ private List<Result> CreateResultsFromQuery(Query query)
129129
{
130130
// Add score to prioritize processes with visible windows
131131
// Use window title for those processes
132-
if (Settings.PutVisibleWindowProcessesTop)
132+
if (_settings.PutVisibleWindowProcessesTop)
133133
{
134134
score += 200;
135135
}
136136
processlist.Add(new ProcessResult(
137137
p,
138138
score,
139-
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
139+
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
140140
score == windowTitleMatch.Score ? windowTitleMatch : null,
141141
progressNameIdTitle));
142142
}
@@ -194,8 +194,8 @@ private List<Result> CreateResultsFromQuery(Query query)
194194
sortedResults.Insert(1, new Result()
195195
{
196196
IcoPath = firstResult?.IcoPath,
197-
Title = string.Format(Context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), firstResult?.ContextData),
198-
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all_count"), processlist.Count),
197+
Title = Localize.flowlauncher_plugin_processkiller_kill_all(firstResult?.ContextData),
198+
SubTitle = Localize.flowlauncher_plugin_processkiller_kill_all_count(processlist.Count),
199199
Score = 200,
200200
Action = (c) =>
201201
{

0 commit comments

Comments
 (0)