diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs b/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs index b3f5a8b4b1e..895515caad6 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs @@ -7,10 +7,10 @@ public enum DecimalSeparator { [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 } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 9d5e4700fff..a20a1ad5dbb 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -5,9 +5,9 @@ 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 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider private const string IcoPath = "Images/calculator.png"; private static readonly List 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 @@ public List Query(Query query) { 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 @@ private static string NormalizeNumber(string numberStr, bool isFunctionPresent, { processedStr = processedStr.Replace(decimalSep, "."); } - + return processedStr; } else @@ -310,7 +310,7 @@ private static string NormalizeNumber(string numberStr, bool isFunctionPresent, return processedStr; } } - + private static bool IsValidGrouping(string[] parts, int[] groupSizes) { if (parts.Length <= 1) return true; @@ -326,7 +326,7 @@ private static bool IsValidGrouping(string[] parts, int[] groupSizes) var lastGroupSize = groupSizes.Last(); var canRepeatLastGroup = lastGroupSize != 0; - + int groupIndex = 0; for (int i = parts.Length - 1; i > 0; i--) { @@ -335,7 +335,7 @@ private static bool IsValidGrouping(string[] parts, int[] groupSizes) { expectedSize = groupSizes[groupIndex]; } - else if(canRepeatLastGroup) + else if (canRepeatLastGroup) { expectedSize = lastGroupSize; } @@ -345,7 +345,7 @@ private static bool IsValidGrouping(string[] parts, int[] groupSizes) } if (parts[i].Length != expectedSize) return false; - + groupIndex++; } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs index cac0f308016..1544dc41fba 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs @@ -1,5 +1,4 @@ - -namespace Flow.Launcher.Plugin.Calculator; +namespace Flow.Launcher.Plugin.Calculator; public class Settings { diff --git a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj index d8db0abe19e..9002a3a4a02 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj +++ b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj @@ -32,6 +32,7 @@ prompt 4 false + $(NoWarn);FLSG0007 @@ -54,5 +55,9 @@ PreserveNewest + + + + \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs index 48717816b0d..503d82cc30a 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs @@ -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 List Query(Query query) + public void Init(PluginInitContext context) { - return QueryResults(query); + Context = context; } - public List HomeQuery() + public List Query(Query query) { - return QueryResults(); + return QueryResults(query); } - private List QueryResults(Query query = null) + private static List QueryResults(Query query = null) { var nonGlobalPlugins = GetNonGlobalPlugins(); var querySearch = query?.Search ?? string.Empty; @@ -34,7 +34,7 @@ from keyword in nonGlobalPlugins.Keys 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 @@ from keyword in nonGlobalPlugins.Keys return false; } }; - return results.ToList(); + return [.. results]; } - private Dictionary GetNonGlobalPlugins() + private static Dictionary GetNonGlobalPlugins() { var nonGlobalPlugins = new Dictionary(); foreach (var plugin in Context.API.GetAllPlugins()) @@ -66,19 +66,19 @@ private Dictionary GetNonGlobalPlugins() return nonGlobalPlugins; } - public void Init(PluginInitContext context) + public string GetTranslatedPluginTitle() { - Context = context; + return Localize.flowlauncher_plugin_pluginindicator_plugin_name(); } - public string GetTranslatedPluginTitle() + public string GetTranslatedPluginDescription() { - return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name"); + return Localize.flowlauncher_plugin_pluginindicator_plugin_description(); } - public string GetTranslatedPluginDescription() + public List HomeQuery() { - return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description"); + return QueryResults(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Flow.Launcher.Plugin.ProcessKiller.csproj b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Flow.Launcher.Plugin.ProcessKiller.csproj index 0a7a02a452e..39586771f8c 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Flow.Launcher.Plugin.ProcessKiller.csproj +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Flow.Launcher.Plugin.ProcessKiller.csproj @@ -35,6 +35,7 @@ prompt 4 false + $(NoWarn);FLSG0007 @@ -52,6 +53,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs index 8f5ba4bd237..44746fa6201 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs @@ -9,19 +9,19 @@ namespace Flow.Launcher.Plugin.ProcessKiller { public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider { - private readonly ProcessHelper processHelper = new(); + internal static PluginInitContext Context { get; private set; } - private static PluginInitContext _context; + private Settings _settings; - internal Settings Settings; + private readonly ProcessHelper processHelper = new(); private SettingsViewModel _viewModel; public void Init(PluginInitContext context) { - _context = context; - Settings = context.API.LoadSettingJsonStorage(); - _viewModel = new SettingsViewModel(Settings); + Context = context; + _settings = context.API.LoadSettingJsonStorage(); + _viewModel = new SettingsViewModel(_settings); } public List Query(Query query) @@ -31,12 +31,12 @@ public List Query(Query query) 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 LoadContextMenus(Result result) @@ -51,13 +51,13 @@ public List LoadContextMenus(Result result) { 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 @@ public List LoadContextMenus(Result result) private List 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 @@ private List CreateResultsFromQuery(Query query) var searchTerm = query.Search; var processlist = new List(); var processWindowTitle = - Settings.ShowWindowTitle || Settings.PutVisibleWindowProcessesTop ? + _settings.ShowWindowTitle || _settings.PutVisibleWindowProcessesTop ? ProcessHelper.GetProcessesWithNonEmptyWindowTitle() : - new Dictionary(); + []; if (string.IsNullOrWhiteSpace(searchTerm)) { - foreach (var p in allPocessList) + foreach (var p in allProcessList) { var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p); @@ -97,8 +97,8 @@ private List CreateResultsFromQuery(Query query) // 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 @@ private List CreateResultsFromQuery(Query query) } 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 @@ private List CreateResultsFromQuery(Query query) 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 @@ private List CreateResultsFromQuery(Query query) 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 @@ private List CreateResultsFromQuery(Query query) 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; } }); diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs index cea34f7dc57..0e2f78f872c 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs @@ -16,8 +16,8 @@ internal class ProcessHelper { private static readonly string ClassName = nameof(ProcessHelper); - private readonly HashSet _systemProcessList = new() - { + private readonly HashSet _systemProcessList = + [ "conhost", "svchost", "idle", @@ -31,12 +31,12 @@ internal class ProcessHelper "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 @@ public IEnumerable GetSimilarProcesses(string processPath) 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 @@ public void TryKill(PluginInitContext context, Process p) } 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 { diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessResult.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessResult.cs index 146c9c92cf8..10a1ebe4af7 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessResult.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessResult.cs @@ -3,25 +3,16 @@ 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; } } diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ViewModels/SettingsViewModel.cs index 0728d9c0fb5..02690b9e53b 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ViewModels/SettingsViewModel.cs @@ -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; } } diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml index b969be4e877..761570affb1 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml @@ -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}" /> + IsChecked="{Binding Settings.PutVisibleWindowProcessesTop}" /> \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml.cs index a066ab6a912..7e712da6120 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/Views/SettingsControl.xaml.cs @@ -5,9 +5,6 @@ namespace Flow.Launcher.Plugin.ProcessKiller.Views; public partial class SettingsControl : UserControl { - /// - /// Interaction logic for SettingsControl.xaml - /// public SettingsControl(SettingsViewModel viewModel) { InitializeComponent(); diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Flow.Launcher.Plugin.Shell.csproj b/Plugins/Flow.Launcher.Plugin.Shell/Flow.Launcher.Plugin.Shell.csproj index 5c3475133b1..e6932709f74 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Flow.Launcher.Plugin.Shell.csproj +++ b/Plugins/Flow.Launcher.Plugin.Shell/Flow.Launcher.Plugin.Shell.csproj @@ -34,6 +34,7 @@ prompt 4 false + $(NoWarn);FLSG0007 @@ -58,6 +59,7 @@ + diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index a86b96800c2..2440facd023 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -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 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, IDispo { 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 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, IDispo public List Query(Query query) { - List results = new List(); + List results = []; string cmd = query.Search; if (string.IsNullOrEmpty(cmd)) { @@ -45,7 +45,7 @@ public List Query(Query query) 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 @@ public List Query(Query query) { 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 @@ private List GetHistoryCmds(string cmd, Result result) { 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 @@ private List GetHistoryCmds(string cmd, Result result) }).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 @@ private Result GetCurrentCmd(string cmd) { 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 @@ private List ResultsFromHistory() .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 @@ private List ResultsFromHistory() }); 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 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin 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 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin 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 @@ private void Execute(Func startProcess, ProcessStartI 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 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) 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 @@ public Control CreateSettingPanel() 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 LoadContextMenus(Result selectedResult) @@ -442,7 +442,7 @@ public List LoadContextMenus(Result selectedResult) { 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 @@ public List LoadContextMenus(Result selectedResult) }, 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 @@ public List LoadContextMenus(Result selectedResult) }, new() { - Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_copy"), + Title = Localize.flowlauncher_plugin_cmd_copy(), Action = c => { Context.API.CopyToClipboard(selectedResult.Title); diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs index 9ce2293a200..4616a18ecbd 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs @@ -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 @@ public class Settings public int ShowOnlyMostUsedCMDsNumber { get; set; } - public Dictionary CommandHistory { get; set; } = new Dictionary(); + public Dictionary 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); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs index d87c6c7bfc6..0abc823e088 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs @@ -19,18 +19,18 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) 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() { 5, 10, 20 }; @@ -137,7 +137,6 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) { _settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem; }; - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs index 8797bf2201e..d0669252d75 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/CommandKeywordSetting.xaml.cs @@ -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 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e) 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 { diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj b/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj index 44fc9a8cf72..4cf09baab5a 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj +++ b/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj @@ -34,6 +34,7 @@ prompt 4 false + $(NoWarn);FLSG0007 @@ -58,6 +59,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 56899eef30c..9e9a2f93d49 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -78,4 +78,9 @@ System Commands Provides System related commands. e.g. shutdown, lock, settings etc. + + This theme supports two (light/dark) modes and Blur Transparent Background + This theme supports two (light/dark) modes + This theme supports Blur Transparent Background + diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 77278a0545c..89067d44c0c 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -4,6 +4,7 @@ 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 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} }; - private readonly Dictionary KeywordDescriptionMappings = new(); + private readonly Dictionary 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 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n 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 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 @@ public List Query(Query query) } // 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 @@ private string GetTitle(string key) { 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(); _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 @@ private static unsafe bool EnableShutdownPrivilege() } } - private List Commands(Query query) + private static List Commands(Query query) { var results = new List(); var recycleBinFolder = "shell:RecycleBinFolder"; - results.AddRange(new[] - { + results.AddRange( + [ new Result { Title = "Shutdown", @@ -207,9 +206,9 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) IcoPath = "Images\\app.png", Action = c => { - _context.API.RestartApp(); + Context.API.RestartApp(); return false; } }, @@ -403,8 +402,8 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) IcoPath = "Images\\checkupdate.png", Action = c => { - _context.API.HideMainWindow(); - _context.API.CheckForNewUpdate(); + Context.API.HideMainWindow(); + Context.API.CheckForNewUpdate(); return true; } }, @@ -445,11 +443,11 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) AutoCompleteText = Documentation, Action = c => { - _context.API.OpenUrl(Documentation); + Context.API.OpenUrl(Documentation); return true; } }, @@ -471,11 +469,11 @@ private List Commands(Query query) 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 @@ private List Commands(Query query) Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"), Action = c => { - _context.API.ToggleGameMode(); + Context.API.ToggleGameMode(); return true; } }, @@ -499,29 +497,29 @@ private List Commands(Query query) { 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 _) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs index f39e6d65fe0..96a545e742c 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs @@ -13,8 +13,8 @@ public Settings() } } - public ObservableCollection Commands { get; set; } = new ObservableCollection - { + public ObservableCollection Commands { get; set; } = + [ new() { Key = "Shutdown", @@ -120,7 +120,7 @@ public Settings() Key = "Set Flow Launcher Theme", Keyword = "Set Flow Launcher Theme" } - }; + ]; [JsonIgnore] public Command SelectedCommand { get; set; } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs index 0755dffa923..bda8c6c048d 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs @@ -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; } } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs index 1a8621eeb97..9906db46dff 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs @@ -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 @@ private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) 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(); } } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index f8aeaeafdff..50b1063efaa 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -4,40 +4,30 @@ 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) - { - _context = context; - } - - public List Query(Query query) + public static List 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 highlightData) + private static Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList highlightData) { string title; if (theme == selectedTheme) @@ -53,17 +43,28 @@ private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int s 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 @@ private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int s Score = score, Action = c => { - if (_context.API.SetCurrentTheme(theme)) + if (Main.Context.API.SetCurrentTheme(theme)) { - _context.API.ReQuery(); + Main.Context.API.ReQuery(); } return false; } diff --git a/Plugins/Flow.Launcher.Plugin.Url/Flow.Launcher.Plugin.Url.csproj b/Plugins/Flow.Launcher.Plugin.Url/Flow.Launcher.Plugin.Url.csproj index fdfe03224c1..091248cfdf3 100644 --- a/Plugins/Flow.Launcher.Plugin.Url/Flow.Launcher.Plugin.Url.csproj +++ b/Plugins/Flow.Launcher.Plugin.Url/Flow.Launcher.Plugin.Url.csproj @@ -33,6 +33,7 @@ prompt 4 false + $(NoWarn);FLSG0007 @@ -56,4 +57,8 @@ + + + + diff --git a/Plugins/Flow.Launcher.Plugin.Url/Main.cs b/Plugins/Flow.Launcher.Plugin.Url/Main.cs index 9fa52c8da54..db7cecbdebb 100644 --- a/Plugins/Flow.Launcher.Plugin.Url/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Url/Main.cs @@ -40,7 +40,7 @@ public class Main : IPlugin, IPluginI18n "(?:/\\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 Query(Query query) @@ -53,7 +53,7 @@ public List Query(Query query) 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 @@ public List Query(Query query) } 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 @@ public bool IsURL(string raw) public void Init(PluginInitContext context) { - this.context = context; + Context = context; _settings = context.API.LoadSettingJsonStorage(); } 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(); } } }