Code cleanup & Use Flow.Launcher.Localization to improve code quality (#4009)

* Use Flow.Launcher.Localization to improve code quality

* Code cleanup

* Improve code quality

* Improve code quality

* Use internal static Context & Improve code quality

* Use Flow.Launcher.Localization to improve code quality

* Code cleanup

* Use Flow.Launcher.Localization to improve code quality

* Improve code quality

* Improve code quality

* Use Flow.Launcher.Localization to improve code quality

* Fix logic issue

* Fix the variable name typo

* Fix redundant boolean cast and ensure consistent default value handling

* Use Flow.Launcher.Localization to improve code quality

* Revert namespace styles

* Fix indent format

* Revert namespace style

* Fix indent format

* Fix namespace style

* Fix indent format

* Fix indent format
This commit is contained in:
Jack Ye 2025-09-28 00:18:33 +08:00 committed by GitHub
parent 2d00ab1d3e
commit 5b6ea73513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 252 additions and 273 deletions

View file

@ -7,10 +7,10 @@ namespace Flow.Launcher.Plugin.Calculator
{
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_use_system_locale))]
UseSystemLocale,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_dot))]
Dot,
Dot,
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_comma))]
Comma
}

View file

@ -5,9 +5,9 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using Mages.Core;
using Flow.Launcher.Plugin.Calculator.Views;
using Flow.Launcher.Plugin.Calculator.ViewModels;
using Flow.Launcher.Plugin.Calculator.Views;
using Mages.Core;
namespace Flow.Launcher.Plugin.Calculator
{
@ -26,7 +26,7 @@ namespace Flow.Launcher.Plugin.Calculator
private const string IcoPath = "Images/calculator.png";
private static readonly List<Result> EmptyResults = [];
internal static PluginInitContext Context { get; set; } = null!;
internal static PluginInitContext Context { get; private set; } = null!;
private Settings _settings;
private SettingsViewModel _viewModel;
@ -57,10 +57,10 @@ namespace Flow.Launcher.Plugin.Calculator
{
var search = query.Search;
bool isFunctionPresent = FunctionRegex.IsMatch(search);
// Mages is case sensitive, so we need to convert all function names to lower case.
search = FunctionRegex.Replace(search, m => m.Value.ToLowerInvariant());
var decimalSep = GetDecimalSeparator();
var groupSep = GetGroupSeparator(decimalSep);
var expression = NumberRegex.Replace(search, m => NormalizeNumber(m.Value, isFunctionPresent, decimalSep, groupSep));
@ -292,7 +292,7 @@ namespace Flow.Launcher.Plugin.Calculator
{
processedStr = processedStr.Replace(decimalSep, ".");
}
return processedStr;
}
else
@ -310,7 +310,7 @@ namespace Flow.Launcher.Plugin.Calculator
return processedStr;
}
}
private static bool IsValidGrouping(string[] parts, int[] groupSizes)
{
if (parts.Length <= 1) return true;
@ -326,7 +326,7 @@ namespace Flow.Launcher.Plugin.Calculator
var lastGroupSize = groupSizes.Last();
var canRepeatLastGroup = lastGroupSize != 0;
int groupIndex = 0;
for (int i = parts.Length - 1; i > 0; i--)
{
@ -335,7 +335,7 @@ namespace Flow.Launcher.Plugin.Calculator
{
expectedSize = groupSizes[groupIndex];
}
else if(canRepeatLastGroup)
else if (canRepeatLastGroup)
{
expectedSize = lastGroupSize;
}
@ -345,7 +345,7 @@ namespace Flow.Launcher.Plugin.Calculator
}
if (parts[i].Length != expectedSize) return false;
groupIndex++;
}

View file

@ -1,5 +1,4 @@

namespace Flow.Launcher.Plugin.Calculator;
namespace Flow.Launcher.Plugin.Calculator;
public class Settings
{

View file

@ -32,6 +32,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -54,5 +55,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
</ItemGroup>
</Project>

View file

@ -5,19 +5,19 @@ namespace Flow.Launcher.Plugin.PluginIndicator
{
public class Main : IPlugin, IPluginI18n, IHomeQuery
{
internal PluginInitContext Context { get; private set; }
internal static PluginInitContext Context { get; private set; }
public void Init(PluginInitContext context)
{
Context = context;
}
public List<Result> Query(Query query)
{
return QueryResults(query);
}
public List<Result> HomeQuery()
{
return QueryResults();
}
private List<Result> QueryResults(Query query = null)
private static List<Result> QueryResults(Query query = null)
{
var nonGlobalPlugins = GetNonGlobalPlugins();
var querySearch = query?.Search ?? string.Empty;
@ -34,7 +34,7 @@ namespace Flow.Launcher.Plugin.PluginIndicator
select new Result
{
Title = keyword,
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_result_subtitle"), plugin.Name),
SubTitle = Localize.flowlauncher_plugin_pluginindicator_result_subtitle(plugin.Name),
Score = score,
IcoPath = plugin.IcoPath,
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
@ -44,10 +44,10 @@ namespace Flow.Launcher.Plugin.PluginIndicator
return false;
}
};
return results.ToList();
return [.. results];
}
private Dictionary<string, PluginPair> GetNonGlobalPlugins()
private static Dictionary<string, PluginPair> GetNonGlobalPlugins()
{
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
foreach (var plugin in Context.API.GetAllPlugins())
@ -66,19 +66,19 @@ namespace Flow.Launcher.Plugin.PluginIndicator
return nonGlobalPlugins;
}
public void Init(PluginInitContext context)
{
Context = context;
}
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
return Localize.flowlauncher_plugin_pluginindicator_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
return Localize.flowlauncher_plugin_pluginindicator_plugin_description();
}
public List<Result> HomeQuery()
{
return QueryResults();
}
}
}

View file

@ -35,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -52,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -9,19 +9,19 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
{
internal static PluginInitContext Context { get; private set; }
private Settings _settings;
private readonly ProcessHelper processHelper = new();
private static PluginInitContext _context;
internal Settings Settings;
private SettingsViewModel _viewModel;
public void Init(PluginInitContext context)
{
_context = context;
Settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(Settings);
Context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(_settings);
}
public List<Result> Query(Query query)
@ -31,12 +31,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
public string GetTranslatedPluginTitle()
{
return _context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_name");
return Localize.flowlauncher_plugin_processkiller_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return _context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_description");
return Localize.flowlauncher_plugin_processkiller_plugin_description();
}
public List<Result> LoadContextMenus(Result result)
@ -51,13 +51,13 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
menuOptions.Add(new Result
{
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
Title = Localize.flowlauncher_plugin_processkiller_kill_instances(),
SubTitle = processPath,
Action = _ =>
{
foreach (var p in similarProcesses)
{
processHelper.TryKill(_context, p);
ProcessHelper.TryKill(p);
}
return true;
@ -72,8 +72,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
private List<Result> CreateResultsFromQuery(Query query)
{
// Get all non-system processes
var allPocessList = processHelper.GetMatchingProcesses();
if (!allPocessList.Any())
var allProcessList = processHelper.GetMatchingProcesses();
if (allProcessList.Count == 0)
{
return null;
}
@ -82,12 +82,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
var searchTerm = query.Search;
var processlist = new List<ProcessResult>();
var processWindowTitle =
Settings.ShowWindowTitle || Settings.PutVisibleWindowProcessesTop ?
_settings.ShowWindowTitle || _settings.PutVisibleWindowProcessesTop ?
ProcessHelper.GetProcessesWithNonEmptyWindowTitle() :
new Dictionary<int, string>();
[];
if (string.IsNullOrWhiteSpace(searchTerm))
{
foreach (var p in allPocessList)
foreach (var p in allProcessList)
{
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
@ -97,8 +97,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
// Use window title for those processes if enabled
processlist.Add(new ProcessResult(
p,
Settings.PutVisibleWindowProcessesTop ? 200 : 0,
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
_settings.PutVisibleWindowProcessesTop ? 200 : 0,
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
null,
progressNameIdTitle));
}
@ -115,35 +115,35 @@ namespace Flow.Launcher.Plugin.ProcessKiller
}
else
{
foreach (var p in allPocessList)
foreach (var p in allProcessList)
{
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
if (processWindowTitle.TryGetValue(p.Id, out var windowTitle))
{
// Get max score from searching process name, window title and process id
var windowTitleMatch = _context.API.FuzzySearch(searchTerm, windowTitle);
var processNameIdMatch = _context.API.FuzzySearch(searchTerm, progressNameIdTitle);
var windowTitleMatch = Context.API.FuzzySearch(searchTerm, windowTitle);
var processNameIdMatch = Context.API.FuzzySearch(searchTerm, progressNameIdTitle);
var score = Math.Max(windowTitleMatch.Score, processNameIdMatch.Score);
if (score > 0)
{
// Add score to prioritize processes with visible windows
// Use window title for those processes
if (Settings.PutVisibleWindowProcessesTop)
if (_settings.PutVisibleWindowProcessesTop)
{
score += 200;
}
processlist.Add(new ProcessResult(
p,
score,
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
score == windowTitleMatch.Score ? windowTitleMatch : null,
progressNameIdTitle));
}
}
else
{
var processNameIdMatch = _context.API.FuzzySearch(searchTerm, progressNameIdTitle);
var processNameIdMatch = Context.API.FuzzySearch(searchTerm, progressNameIdTitle);
var score = processNameIdMatch.Score;
if (score > 0)
{
@ -162,7 +162,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
foreach (var pr in processlist)
{
var p = pr.Process;
var path = processHelper.TryGetProcessFilename(p);
var path = ProcessHelper.TryGetProcessFilename(p);
results.Add(new Result()
{
IcoPath = path,
@ -172,12 +172,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
TitleHighlightData = pr.TitleMatch?.MatchData,
Score = pr.Score,
ContextData = p.ProcessName,
AutoCompleteText = $"{_context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
Action = (c) =>
{
processHelper.TryKill(_context, p);
ProcessHelper.TryKill(p);
// Re-query to refresh process list
_context.API.ReQuery();
Context.API.ReQuery();
return true;
}
});
@ -194,17 +194,17 @@ namespace Flow.Launcher.Plugin.ProcessKiller
sortedResults.Insert(1, new Result()
{
IcoPath = firstResult?.IcoPath,
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), firstResult?.ContextData),
SubTitle = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all_count"), processlist.Count),
Title = Localize.flowlauncher_plugin_processkiller_kill_all(firstResult?.ContextData),
SubTitle = Localize.flowlauncher_plugin_processkiller_kill_all_count(processlist.Count),
Score = 200,
Action = (c) =>
{
foreach (var p in processlist)
{
processHelper.TryKill(_context, p.Process);
ProcessHelper.TryKill(p.Process);
}
// Re-query to refresh process list
_context.API.ReQuery();
Context.API.ReQuery();
return true;
}
});

View file

@ -16,8 +16,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
private static readonly string ClassName = nameof(ProcessHelper);
private readonly HashSet<string> _systemProcessList = new()
{
private readonly HashSet<string> _systemProcessList =
[
"conhost",
"svchost",
"idle",
@ -31,12 +31,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
"winlogon",
"services",
"spoolsv",
"explorer"
};
"explorer"
];
private const string FlowLauncherProcessName = "Flow.Launcher";
private bool IsSystemProcessOrFlowLauncher(Process p) =>
private bool IsSystemProcessOrFlowLauncher(Process p) =>
_systemProcessList.Contains(p.ProcessName.ToLower()) ||
string.Equals(p.ProcessName, FlowLauncherProcessName, StringComparison.OrdinalIgnoreCase);
@ -142,7 +142,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return Process.GetProcesses().Where(p => !IsSystemProcessOrFlowLauncher(p) && TryGetProcessFilename(p) == processPath);
}
public void TryKill(PluginInitContext context, Process p)
public static void TryKill(Process p)
{
try
{
@ -154,11 +154,11 @@ namespace Flow.Launcher.Plugin.ProcessKiller
}
catch (Exception e)
{
context.API.LogException(ClassName, $"Failed to kill process {p.ProcessName}", e);
Main.Context.API.LogException(ClassName, $"Failed to kill process {p.ProcessName}", e);
}
}
public unsafe string TryGetProcessFilename(Process p)
public static unsafe string TryGetProcessFilename(Process p)
{
try
{

View file

@ -3,25 +3,16 @@ using Flow.Launcher.Plugin.SharedModels;
namespace Flow.Launcher.Plugin.ProcessKiller
{
internal class ProcessResult
internal class ProcessResult(Process process, int score, string title, MatchResult match, string tooltip)
{
public ProcessResult(Process process, int score, string title, MatchResult match, string tooltip)
{
Process = process;
Score = score;
Title = title;
TitleMatch = match;
Tooltip = tooltip;
}
public Process Process { get; } = process;
public Process Process { get; }
public int Score { get; } = score;
public int Score { get; }
public string Title { get; } = title;
public string Title { get; }
public MatchResult TitleMatch { get; } = match;
public MatchResult TitleMatch { get; }
public string Tooltip { get; }
public string Tooltip { get; } = tooltip;
}
}

View file

@ -1,24 +1,7 @@
namespace Flow.Launcher.Plugin.ProcessKiller.ViewModels
{
public class SettingsViewModel
public class SettingsViewModel(Settings settings)
{
public Settings Settings { get; set; }
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
public bool ShowWindowTitle
{
get => Settings.ShowWindowTitle;
set => Settings.ShowWindowTitle = value;
}
public bool PutVisibleWindowProcessesTop
{
get => Settings.PutVisibleWindowProcessesTop;
set => Settings.PutVisibleWindowProcessesTop = value;
}
public Settings Settings { get; set; } = settings;
}
}

View file

@ -4,6 +4,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Flow.Launcher.Plugin.ProcessKiller.ViewModels"
d:DataContext="{d:DesignInstance Type=vm:SettingsViewModel}"
d:DesignHeight="300"
d:DesignWidth="500"
mc:Ignorable="d">
@ -18,11 +20,11 @@
Grid.Row="0"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
Content="{DynamicResource flowlauncher_plugin_processkiller_show_window_title}"
IsChecked="{Binding ShowWindowTitle}" />
IsChecked="{Binding Settings.ShowWindowTitle}" />
<CheckBox
Grid.Row="1"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
IsChecked="{Binding PutVisibleWindowProcessesTop}" />
IsChecked="{Binding Settings.PutVisibleWindowProcessesTop}" />
</Grid>
</UserControl>

View file

@ -5,9 +5,6 @@ namespace Flow.Launcher.Plugin.ProcessKiller.Views;
public partial class SettingsControl : UserControl
{
/// <summary>
/// Interaction logic for SettingsControl.xaml
/// </summary>
public SettingsControl(SettingsViewModel viewModel)
{
InitializeComponent();

View file

@ -34,6 +34,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -58,6 +59,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
<PackageReference Include="InputSimulator" Version="1.0.4" NoWarn="NU1701" />
</ItemGroup>

View file

@ -1,13 +1,13 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.SharedCommands;
using WindowsInput;
using WindowsInput.Native;
using Flow.Launcher.Plugin.SharedCommands;
using Control = System.Windows.Controls.Control;
using Keys = System.Windows.Forms.Keys;
@ -17,7 +17,7 @@ namespace Flow.Launcher.Plugin.Shell
{
private static readonly string ClassName = nameof(Main);
internal PluginInitContext Context { get; private set; }
internal static PluginInitContext Context { get; private set; }
private const string Image = "Images/shell.png";
private bool _winRStroked;
@ -27,7 +27,7 @@ namespace Flow.Launcher.Plugin.Shell
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
List<Result> results = [];
string cmd = query.Search;
if (string.IsNullOrEmpty(cmd))
{
@ -45,7 +45,7 @@ namespace Flow.Launcher.Plugin.Shell
string basedir = null;
string dir = null;
string excmd = Environment.ExpandEnvironmentVariables(cmd);
if (Directory.Exists(excmd) && (cmd.EndsWith("/") || cmd.EndsWith(@"\")))
if (Directory.Exists(excmd) && (cmd.EndsWith('/') || cmd.EndsWith('\\')))
{
basedir = excmd;
dir = cmd;
@ -54,7 +54,7 @@ namespace Flow.Launcher.Plugin.Shell
{
basedir = Path.GetDirectoryName(excmd);
var dirName = Path.GetDirectoryName(cmd);
dir = (dirName.EndsWith("/") || dirName.EndsWith(@"\")) ? dirName : cmd[..(dirName.Length + 1)];
dir = (dirName.EndsWith('/') || dirName.EndsWith('\\')) ? dirName : cmd[..(dirName.Length + 1)];
}
if (basedir != null)
@ -103,14 +103,14 @@ namespace Flow.Launcher.Plugin.Shell
{
if (m.Key == cmd)
{
result.SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value);
result.SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value);
return null;
}
var ret = new Result
{
Title = m.Key,
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value),
SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value),
IcoPath = Image,
Action = c =>
{
@ -129,9 +129,9 @@ namespace Flow.Launcher.Plugin.Shell
}).Where(o => o != null);
if (_settings.ShowOnlyMostUsedCMDs)
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
return [.. history.Take(_settings.ShowOnlyMostUsedCMDsNumber)];
return history.ToList();
return [.. history];
}
private Result GetCurrentCmd(string cmd)
@ -140,7 +140,7 @@ namespace Flow.Launcher.Plugin.Shell
{
Title = cmd,
Score = 5000,
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_cmd_execute_through_shell"),
SubTitle = Localize.flowlauncher_plugin_cmd_execute_through_shell(),
IcoPath = Image,
Action = c =>
{
@ -165,7 +165,7 @@ namespace Flow.Launcher.Plugin.Shell
.Select(m => new Result
{
Title = m.Key,
SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_cmd_has_been_executed_times"), m.Value),
SubTitle = Localize.flowlauncher_plugin_cmd_cmd_has_been_executed_times(m.Value),
IcoPath = Image,
Action = c =>
{
@ -182,9 +182,9 @@ namespace Flow.Launcher.Plugin.Shell
});
if (_settings.ShowOnlyMostUsedCMDs)
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
return [.. history.Take(_settings.ShowOnlyMostUsedCMDsNumber)];
return history.ToList();
return [.. history];
}
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false)
@ -199,7 +199,7 @@ namespace Flow.Launcher.Plugin.Shell
Verb = runAsAdministratorArg,
WorkingDirectory = workingDirectory,
};
var notifyStr = Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close");
var notifyStr = Localize.flowlauncher_plugin_cmd_press_any_key_to_close();
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
switch (_settings.Shell)
{
@ -288,10 +288,10 @@ namespace Flow.Launcher.Plugin.Shell
case Shell.RunCommand:
{
var parts = command.Split(new[]
{
var parts = command.Split(
[
' '
}, 2);
], 2);
if (parts.Length == 2)
{
var filename = parts[0];
@ -336,12 +336,12 @@ namespace Flow.Launcher.Plugin.Shell
catch (FileNotFoundException e)
{
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_command_not_found"), e.Message));
Localize.flowlauncher_plugin_cmd_command_not_found(e.Message));
}
catch (Win32Exception e)
{
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
string.Format(Context.API.GetTranslation("flowlauncher_plugin_cmd_error_running_command"), e.Message));
Localize.flowlauncher_plugin_cmd_error_running_command(e.Message));
}
catch (Exception e)
{
@ -405,7 +405,7 @@ namespace Flow.Launcher.Plugin.Shell
return true;
}
private void OnWinRPressed()
private static void OnWinRPressed()
{
Context.API.ShowMainWindow();
// show the main window and set focus to the query box
@ -428,12 +428,12 @@ namespace Flow.Launcher.Plugin.Shell
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("flowlauncher_plugin_cmd_plugin_name");
return Localize.flowlauncher_plugin_cmd_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return Context.API.GetTranslation("flowlauncher_plugin_cmd_plugin_description");
return Localize.flowlauncher_plugin_cmd_plugin_description();
}
public List<Result> LoadContextMenus(Result selectedResult)
@ -442,7 +442,7 @@ namespace Flow.Launcher.Plugin.Shell
{
new()
{
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"),
Title = Localize.flowlauncher_plugin_cmd_run_as_different_user(),
Action = c =>
{
Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title));
@ -453,7 +453,7 @@ namespace Flow.Launcher.Plugin.Shell
},
new()
{
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_administrator"),
Title = Localize.flowlauncher_plugin_cmd_run_as_administrator(),
Action = c =>
{
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
@ -464,7 +464,7 @@ namespace Flow.Launcher.Plugin.Shell
},
new()
{
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_copy"),
Title = Localize.flowlauncher_plugin_cmd_copy(),
Action = c =>
{
Context.API.CopyToClipboard(selectedResult.Title);

View file

@ -5,11 +5,11 @@ namespace Flow.Launcher.Plugin.Shell
public class Settings
{
public Shell Shell { get; set; } = Shell.Cmd;
public bool ReplaceWinR { get; set; } = false;
public bool CloseShellAfterPress { get; set; } = false;
public bool LeaveShellOpen { get; set; }
public bool RunAsAdministrator { get; set; } = true;
@ -20,18 +20,14 @@ namespace Flow.Launcher.Plugin.Shell
public int ShowOnlyMostUsedCMDsNumber { get; set; }
public Dictionary<string, int> CommandHistory { get; set; } = new Dictionary<string, int>();
public Dictionary<string, int> CommandHistory { get; set; } = [];
public void AddCmdHistory(string cmdName)
{
if (CommandHistory.ContainsKey(cmdName))
if (!CommandHistory.TryAdd(cmdName, 1))
{
CommandHistory[cmdName] += 1;
}
else
{
CommandHistory.Add(cmdName, 1);
}
}
}

View file

@ -19,18 +19,18 @@ namespace Flow.Launcher.Plugin.Shell
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
CloseShellAfterPress.IsChecked = _settings.CloseShellAfterPress;
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;
UseWindowsTerminal.IsChecked = _settings.UseWindowsTerminal;
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;
ShowOnlyMostUsedCMDs.IsChecked = _settings.ShowOnlyMostUsedCMDs;
if ((bool)!ShowOnlyMostUsedCMDs.IsChecked)
if (ShowOnlyMostUsedCMDs.IsChecked != true)
ShowOnlyMostUsedCMDsNumber.IsEnabled = false;
ShowOnlyMostUsedCMDsNumber.ItemsSource = new List<int>() { 5, 10, 20 };
@ -137,7 +137,6 @@ namespace Flow.Launcher.Plugin.Shell
{
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
};
}
}
}

View file

@ -5,15 +5,13 @@ namespace Flow.Launcher.Plugin.Sys
public partial class CommandKeywordSettingWindow
{
private readonly Command _oldSearchSource;
private readonly PluginInitContext _context;
public CommandKeywordSettingWindow(PluginInitContext context, Command old)
public CommandKeywordSettingWindow(Command old)
{
_context = context;
_oldSearchSource = old;
InitializeComponent();
CommandKeyword.Text = old.Keyword;
CommandKeywordTips.Text = string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_custom_command_keyword_tip"), old.Name);
CommandKeywordTips.Text = Localize.flowlauncher_plugin_sys_custom_command_keyword_tip(old.Name);
}
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
@ -26,8 +24,8 @@ namespace Flow.Launcher.Plugin.Sys
var keyword = CommandKeyword.Text;
if (string.IsNullOrEmpty(keyword))
{
var warning = _context.API.GetTranslation("flowlauncher_plugin_sys_input_command_keyword");
_context.API.ShowMsgBox(warning);
var warning = Localize.flowlauncher_plugin_sys_input_command_keyword();
Main.Context.API.ShowMsgBox(warning);
}
else
{

View file

@ -34,6 +34,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -58,6 +59,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -78,4 +78,9 @@
<system:String x:Key="flowlauncher_plugin_sys_plugin_name">System Commands</system:String>
<system:String x:Key="flowlauncher_plugin_sys_plugin_description">Provides System related commands. e.g. shutdown, lock, settings etc.</system:String>
<!-- Theme Selector -->
<system:String x:Key="flowlauncher_plugin_sys_type_isdark_hasblur">This theme supports two (light/dark) modes and Blur Transparent Background</system:String>
<system:String x:Key="flowlauncher_plugin_sys_type_isdark">This theme supports two (light/dark) modes</system:String>
<system:String x:Key="flowlauncher_plugin_sys_type_hasblur">This theme supports Blur Transparent Background</system:String>
</ResourceDictionary>

View file

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using Windows.Win32;
using Windows.Win32.Foundation;
@ -42,7 +43,7 @@ namespace Flow.Launcher.Plugin.Sys
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
{"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"}
};
private readonly Dictionary<string, string> KeywordDescriptionMappings = new();
private readonly Dictionary<string, string> KeywordDescriptionMappings = [];
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure,
// software updates, or other predefined reasons.
@ -52,22 +53,21 @@ namespace Flow.Launcher.Plugin.Sys
private const string Documentation = "https://flowlauncher.com/docs/#/usage-tips";
private PluginInitContext _context;
internal static PluginInitContext Context { get; private set; }
private Settings _settings;
private ThemeSelector _themeSelector;
private SettingsViewModel _viewModel;
public Control CreateSettingPanel()
{
UpdateLocalizedNameDescription(false);
return new SysSettings(_context, _viewModel);
return new SysSettings(_viewModel);
}
public List<Result> Query(Query query)
{
if(query.Search.StartsWith(ThemeSelector.Keyword))
if (query.Search.StartsWith(ThemeSelector.Keyword))
{
return _themeSelector.Query(query);
return ThemeSelector.Query(query);
}
var commands = Commands(query);
@ -85,9 +85,9 @@ namespace Flow.Launcher.Plugin.Sys
}
// Match from localized title & localized subtitle & keyword
var titleMatch = _context.API.FuzzySearch(query.Search, c.Title);
var subTitleMatch = _context.API.FuzzySearch(query.Search, c.SubTitle);
var keywordMatch = _context.API.FuzzySearch(query.Search, command.Keyword);
var titleMatch = Context.API.FuzzySearch(query.Search, c.Title);
var subTitleMatch = Context.API.FuzzySearch(query.Search, c.SubTitle);
var keywordMatch = Context.API.FuzzySearch(query.Search, command.Keyword);
// Get the largest score from them
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
@ -113,30 +113,29 @@ namespace Flow.Launcher.Plugin.Sys
{
if (!KeywordTitleMappings.TryGetValue(key, out var translationKey))
{
_context.API.LogError(ClassName, $"Title not found for: {key}");
Context.API.LogError(ClassName, $"Title not found for: {key}");
return "Title Not Found";
}
return _context.API.GetTranslation(translationKey);
return Context.API.GetTranslation(translationKey);
}
private string GetDescription(string key)
{
if (!KeywordDescriptionMappings.TryGetValue(key, out var translationKey))
{
_context.API.LogError(ClassName, $"Description not found for: {key}");
Context.API.LogError(ClassName, $"Description not found for: {key}");
return "Description Not Found";
}
return _context.API.GetTranslation(translationKey);
return Context.API.GetTranslation(translationKey);
}
public void Init(PluginInitContext context)
{
_context = context;
Context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(_settings);
_themeSelector = new ThemeSelector(context);
foreach (string key in KeywordTitleMappings.Keys)
{
// Remove _cmd in the last of the strings
@ -194,12 +193,12 @@ namespace Flow.Launcher.Plugin.Sys
}
}
private List<Result> Commands(Query query)
private static List<Result> Commands(Query query)
{
var results = new List<Result>();
var recycleBinFolder = "shell:RecycleBinFolder";
results.AddRange(new[]
{
results.AddRange(
[
new Result
{
Title = "Shutdown",
@ -207,9 +206,9 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\shutdown.png",
Action = c =>
{
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
var result = Context.API.ShowMsgBox(
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
Localize.flowlauncher_plugin_sys_shutdown_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -228,9 +227,9 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\restart.png",
Action = c =>
{
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
var result = Context.API.ShowMsgBox(
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
Localize.flowlauncher_plugin_sys_restart_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -249,9 +248,9 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\restart_advanced.png",
Action = c =>
{
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
var result = Context.API.ShowMsgBox(
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
Localize.flowlauncher_plugin_sys_restart_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -270,9 +269,9 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\logoff.png",
Action = c =>
{
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
var result = Context.API.ShowMsgBox(
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
Localize.flowlauncher_plugin_sys_log_off(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -338,9 +337,9 @@ namespace Flow.Launcher.Plugin.Sys
var result = PInvoke.SHEmptyRecycleBin(new(), string.Empty, 0);
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
{
_context.API.ShowMsgBox(
string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed"), Environment.NewLine),
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_error"),
Context.API.ShowMsgBox(
Localize.flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed(Environment.NewLine),
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
MessageBoxButton.OK, MessageBoxImage.Error);
}
@ -366,7 +365,7 @@ namespace Flow.Launcher.Plugin.Sys
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe89f"),
Action = c =>
{
_context.API.HideMainWindow();
Context.API.HideMainWindow();
Application.Current.MainWindow.Close();
return true;
}
@ -378,9 +377,9 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\app.png",
Action = c =>
{
_context.API.SaveAppAllSettings();
_context.API.ShowMsg(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
Context.API.SaveAppAllSettings();
Context.API.ShowMsg(Localize.flowlauncher_plugin_sys_dlgtitle_success(),
Localize.flowlauncher_plugin_sys_dlgtext_all_settings_saved());
return true;
}
},
@ -391,7 +390,7 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\app.png",
Action = c =>
{
_context.API.RestartApp();
Context.API.RestartApp();
return false;
}
},
@ -403,8 +402,8 @@ namespace Flow.Launcher.Plugin.Sys
Action = c =>
{
// Hide the window first then open setting dialog because main window can be topmost window which will still display on top of the setting dialog for a while
_context.API.HideMainWindow();
_context.API.OpenSettingDialog();
Context.API.HideMainWindow();
Context.API.OpenSettingDialog();
return true;
}
},
@ -416,14 +415,13 @@ namespace Flow.Launcher.Plugin.Sys
Action = c =>
{
// Hide the window first then show msg after done because sometimes the reload could take a while, so not to make user think it's frozen.
_context.API.HideMainWindow();
Context.API.HideMainWindow();
_ = _context.API.ReloadAllPluginData().ContinueWith(_ =>
_context.API.ShowMsg(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
_context.API.GetTranslation(
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")),
System.Threading.Tasks.TaskScheduler.Current);
_ = Context.API.ReloadAllPluginData().ContinueWith(_ =>
Context.API.ShowMsg(
Localize.flowlauncher_plugin_sys_dlgtitle_success(),
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
TaskScheduler.Current);
return true;
}
@ -435,8 +433,8 @@ namespace Flow.Launcher.Plugin.Sys
IcoPath = "Images\\checkupdate.png",
Action = c =>
{
_context.API.HideMainWindow();
_context.API.CheckForNewUpdate();
Context.API.HideMainWindow();
Context.API.CheckForNewUpdate();
return true;
}
},
@ -445,11 +443,11 @@ namespace Flow.Launcher.Plugin.Sys
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
Title = "Open Log Location",
IcoPath = "Images\\app.png",
CopyText = _context.API.GetLogDirectory(),
AutoCompleteText = _context.API.GetLogDirectory(),
CopyText = Context.API.GetLogDirectory(),
AutoCompleteText = Context.API.GetLogDirectory(),
Action = c =>
{
_context.API.OpenDirectory(_context.API.GetLogDirectory());
Context.API.OpenDirectory(Context.API.GetLogDirectory());
return true;
}
},
@ -462,7 +460,7 @@ namespace Flow.Launcher.Plugin.Sys
AutoCompleteText = Documentation,
Action = c =>
{
_context.API.OpenUrl(Documentation);
Context.API.OpenUrl(Documentation);
return true;
}
},
@ -471,11 +469,11 @@ namespace Flow.Launcher.Plugin.Sys
Title = "Flow Launcher UserData Folder",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
IcoPath = "Images\\app.png",
CopyText = _context.API.GetDataDirectory(),
AutoCompleteText = _context.API.GetDataDirectory(),
CopyText = Context.API.GetDataDirectory(),
AutoCompleteText = Context.API.GetDataDirectory(),
Action = c =>
{
_context.API.OpenDirectory(_context.API.GetDataDirectory());
Context.API.OpenDirectory(Context.API.GetDataDirectory());
return true;
}
},
@ -486,7 +484,7 @@ namespace Flow.Launcher.Plugin.Sys
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"),
Action = c =>
{
_context.API.ToggleGameMode();
Context.API.ToggleGameMode();
return true;
}
},
@ -499,29 +497,29 @@ namespace Flow.Launcher.Plugin.Sys
{
if (string.IsNullOrEmpty(query.ActionKeyword))
{
_context.API.ChangeQuery($"{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
Context.API.ChangeQuery($"{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
}
else
{
_context.API.ChangeQuery($"{query.ActionKeyword}{Plugin.Query.ActionKeywordSeparator}{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
Context.API.ChangeQuery($"{query.ActionKeyword}{Plugin.Query.ActionKeywordSeparator}{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
}
return false;
}
}
});
]);
return results;
}
public string GetTranslatedPluginTitle()
{
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_name");
return Localize.flowlauncher_plugin_sys_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
return Localize.flowlauncher_plugin_sys_plugin_description();
}
public void OnCultureInfoChanged(CultureInfo _)

View file

@ -13,8 +13,8 @@ public class Settings : BaseModel
}
}
public ObservableCollection<Command> Commands { get; set; } = new ObservableCollection<Command>
{
public ObservableCollection<Command> Commands { get; set; } =
[
new()
{
Key = "Shutdown",
@ -120,7 +120,7 @@ public class Settings : BaseModel
Key = "Set Flow Launcher Theme",
Keyword = "Set Flow Launcher Theme"
}
};
];
[JsonIgnore]
public Command SelectedCommand { get; set; }

View file

@ -1,12 +1,7 @@
namespace Flow.Launcher.Plugin.Sys
{
public class SettingsViewModel
public class SettingsViewModel(Settings settings)
{
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
public Settings Settings { get; }
public Settings Settings { get; } = settings;
}
}

View file

@ -1,17 +1,16 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.Sys
{
public partial class SysSettings : UserControl
{
private readonly PluginInitContext _context;
private readonly Settings _settings;
public SysSettings(PluginInitContext context, SettingsViewModel viewModel)
public SysSettings(SettingsViewModel viewModel)
{
InitializeComponent();
_context = context;
_settings = viewModel.Settings;
DataContext = viewModel;
}
@ -37,15 +36,15 @@ namespace Flow.Launcher.Plugin.Sys
public void OnEditCommandKeywordClick(object sender, RoutedEventArgs e)
{
var commandKeyword = new CommandKeywordSettingWindow(_context, _settings.SelectedCommand);
var commandKeyword = new CommandKeywordSettingWindow(_settings.SelectedCommand);
commandKeyword.ShowDialog();
}
private void MouseDoubleClickItem(object sender, System.Windows.Input.MouseButtonEventArgs e)
private void MouseDoubleClickItem(object sender, MouseButtonEventArgs e)
{
if (((FrameworkElement)e.OriginalSource).DataContext is Command && _settings.SelectedCommand != null)
{
var commandKeyword = new CommandKeywordSettingWindow(_context, _settings.SelectedCommand);
var commandKeyword = new CommandKeywordSettingWindow(_settings.SelectedCommand);
commandKeyword.ShowDialog();
}
}

View file

@ -4,40 +4,30 @@ using Flow.Launcher.Plugin.SharedModels;
namespace Flow.Launcher.Plugin.Sys
{
public class ThemeSelector
public static class ThemeSelector
{
public const string Keyword = "fltheme";
private readonly PluginInitContext _context;
public ThemeSelector(PluginInitContext context)
public static List<Result> Query(Query query)
{
_context = context;
}
public List<Result> Query(Query query)
{
var themes = _context.API.GetAvailableThemes();
var selectedTheme = _context.API.GetCurrentTheme();
var themes = Main.Context.API.GetAvailableThemes();
var selectedTheme = Main.Context.API.GetCurrentTheme();
var search = query.SecondToEndSearch;
if (string.IsNullOrWhiteSpace(search))
{
return themes.Select(x => CreateThemeResult(x, selectedTheme))
.OrderBy(x => x.Title)
.ToList();
return [.. themes.Select(x => CreateThemeResult(x, selectedTheme)).OrderBy(x => x.Title)];
}
return themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)
.ToList();
return [.. themes.Select(theme => (theme, matchResult: Main.Context.API.FuzzySearch(search, theme.Name)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)];
}
private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme) => CreateThemeResult(theme, selectedTheme, 0, null);
private static Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme) => CreateThemeResult(theme, selectedTheme, 0, null);
private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList<int> highlightData)
private static Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList<int> highlightData)
{
string title;
if (theme == selectedTheme)
@ -53,17 +43,28 @@ namespace Flow.Launcher.Plugin.Sys
score = 1000;
}
string description = string.Empty;
string description;
if (theme.IsDark == true)
{
description += _context.API.GetTranslation("TypeIsDarkToolTip");
if (theme.HasBlur == true)
{
description = Localize.flowlauncher_plugin_sys_type_isdark_hasblur();
}
else
{
description = Localize.flowlauncher_plugin_sys_type_isdark();
}
}
if (theme.HasBlur == true)
else
{
if (!string.IsNullOrEmpty(description))
description += " ";
description += _context.API.GetTranslation("TypeHasBlurToolTip");
if (theme.HasBlur == true)
{
description = Localize.flowlauncher_plugin_sys_type_hasblur();
}
else
{
description = string.Empty;
}
}
return new Result
@ -76,9 +77,9 @@ namespace Flow.Launcher.Plugin.Sys
Score = score,
Action = c =>
{
if (_context.API.SetCurrentTheme(theme))
if (Main.Context.API.SetCurrentTheme(theme))
{
_context.API.ReQuery();
Main.Context.API.ReQuery();
}
return false;
}

View file

@ -33,6 +33,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -56,4 +57,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
</ItemGroup>
</Project>

View file

@ -40,7 +40,7 @@ namespace Flow.Launcher.Plugin.Url
"(?:/\\S*)?" +
"$";
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
private PluginInitContext context;
internal static PluginInitContext Context { get; private set; }
private Settings _settings;
public List<Result> Query(Query query)
@ -53,7 +53,7 @@ namespace Flow.Launcher.Plugin.Url
new Result
{
Title = raw,
SubTitle = string.Format(context.API.GetTranslation("flowlauncher_plugin_url_open_url"),raw),
SubTitle = Localize.flowlauncher_plugin_url_open_url(raw),
IcoPath = "Images/url.png",
Score = 8,
Action = _ =>
@ -64,13 +64,13 @@ namespace Flow.Launcher.Plugin.Url
}
try
{
context.API.OpenUrl(raw);
Context.API.OpenUrl(raw);
return true;
}
catch(Exception)
{
context.API.ShowMsgError(string.Format(context.API.GetTranslation("flowlauncher_plugin_url_cannot_open_url"), raw));
Context.API.ShowMsgError(Localize.flowlauncher_plugin_url_cannot_open_url(raw));
return false;
}
}
@ -99,19 +99,19 @@ namespace Flow.Launcher.Plugin.Url
public void Init(PluginInitContext context)
{
this.context = context;
Context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
}
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("flowlauncher_plugin_url_plugin_name");
return Localize.flowlauncher_plugin_url_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("flowlauncher_plugin_url_plugin_description");
return Localize.flowlauncher_plugin_url_plugin_description();
}
}
}