mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
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:
parent
2d00ab1d3e
commit
5b6ea73513
26 changed files with 252 additions and 273 deletions
|
|
@ -7,10 +7,10 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
{
|
{
|
||||||
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_use_system_locale))]
|
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_use_system_locale))]
|
||||||
UseSystemLocale,
|
UseSystemLocale,
|
||||||
|
|
||||||
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_dot))]
|
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_dot))]
|
||||||
Dot,
|
Dot,
|
||||||
|
|
||||||
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_comma))]
|
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_separator_comma))]
|
||||||
Comma
|
Comma
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Mages.Core;
|
|
||||||
using Flow.Launcher.Plugin.Calculator.Views;
|
|
||||||
using Flow.Launcher.Plugin.Calculator.ViewModels;
|
using Flow.Launcher.Plugin.Calculator.ViewModels;
|
||||||
|
using Flow.Launcher.Plugin.Calculator.Views;
|
||||||
|
using Mages.Core;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Calculator
|
namespace Flow.Launcher.Plugin.Calculator
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
private const string IcoPath = "Images/calculator.png";
|
private const string IcoPath = "Images/calculator.png";
|
||||||
private static readonly List<Result> EmptyResults = [];
|
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 Settings _settings;
|
||||||
private SettingsViewModel _viewModel;
|
private SettingsViewModel _viewModel;
|
||||||
|
|
@ -57,10 +57,10 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
{
|
{
|
||||||
var search = query.Search;
|
var search = query.Search;
|
||||||
bool isFunctionPresent = FunctionRegex.IsMatch(search);
|
bool isFunctionPresent = FunctionRegex.IsMatch(search);
|
||||||
|
|
||||||
// Mages is case sensitive, so we need to convert all function names to lower case.
|
// Mages is case sensitive, so we need to convert all function names to lower case.
|
||||||
search = FunctionRegex.Replace(search, m => m.Value.ToLowerInvariant());
|
search = FunctionRegex.Replace(search, m => m.Value.ToLowerInvariant());
|
||||||
|
|
||||||
var decimalSep = GetDecimalSeparator();
|
var decimalSep = GetDecimalSeparator();
|
||||||
var groupSep = GetGroupSeparator(decimalSep);
|
var groupSep = GetGroupSeparator(decimalSep);
|
||||||
var expression = NumberRegex.Replace(search, m => NormalizeNumber(m.Value, isFunctionPresent, decimalSep, groupSep));
|
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, ".");
|
processedStr = processedStr.Replace(decimalSep, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
return processedStr;
|
return processedStr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -310,7 +310,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
return processedStr;
|
return processedStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidGrouping(string[] parts, int[] groupSizes)
|
private static bool IsValidGrouping(string[] parts, int[] groupSizes)
|
||||||
{
|
{
|
||||||
if (parts.Length <= 1) return true;
|
if (parts.Length <= 1) return true;
|
||||||
|
|
@ -326,7 +326,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
|
|
||||||
var lastGroupSize = groupSizes.Last();
|
var lastGroupSize = groupSizes.Last();
|
||||||
var canRepeatLastGroup = lastGroupSize != 0;
|
var canRepeatLastGroup = lastGroupSize != 0;
|
||||||
|
|
||||||
int groupIndex = 0;
|
int groupIndex = 0;
|
||||||
for (int i = parts.Length - 1; i > 0; i--)
|
for (int i = parts.Length - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
|
|
@ -335,7 +335,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
{
|
{
|
||||||
expectedSize = groupSizes[groupIndex];
|
expectedSize = groupSizes[groupIndex];
|
||||||
}
|
}
|
||||||
else if(canRepeatLastGroup)
|
else if (canRepeatLastGroup)
|
||||||
{
|
{
|
||||||
expectedSize = lastGroupSize;
|
expectedSize = lastGroupSize;
|
||||||
}
|
}
|
||||||
|
|
@ -345,7 +345,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts[i].Length != expectedSize) return false;
|
if (parts[i].Length != expectedSize) return false;
|
||||||
|
|
||||||
groupIndex++;
|
groupIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
|
namespace Flow.Launcher.Plugin.Calculator;
|
||||||
namespace Flow.Launcher.Plugin.Calculator;
|
|
||||||
|
|
||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -54,5 +55,9 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -5,19 +5,19 @@ namespace Flow.Launcher.Plugin.PluginIndicator
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, IPluginI18n, IHomeQuery
|
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)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
return QueryResults(query);
|
return QueryResults(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> HomeQuery()
|
private static List<Result> QueryResults(Query query = null)
|
||||||
{
|
|
||||||
return QueryResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Result> QueryResults(Query query = null)
|
|
||||||
{
|
{
|
||||||
var nonGlobalPlugins = GetNonGlobalPlugins();
|
var nonGlobalPlugins = GetNonGlobalPlugins();
|
||||||
var querySearch = query?.Search ?? string.Empty;
|
var querySearch = query?.Search ?? string.Empty;
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Flow.Launcher.Plugin.PluginIndicator
|
||||||
select new Result
|
select new Result
|
||||||
{
|
{
|
||||||
Title = keyword,
|
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,
|
Score = score,
|
||||||
IcoPath = plugin.IcoPath,
|
IcoPath = plugin.IcoPath,
|
||||||
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
|
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
|
||||||
|
|
@ -44,10 +44,10 @@ namespace Flow.Launcher.Plugin.PluginIndicator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return results.ToList();
|
return [.. results];
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, PluginPair> GetNonGlobalPlugins()
|
private static Dictionary<string, PluginPair> GetNonGlobalPlugins()
|
||||||
{
|
{
|
||||||
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
|
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||||
foreach (var plugin in Context.API.GetAllPlugins())
|
foreach (var plugin in Context.API.GetAllPlugins())
|
||||||
|
|
@ -66,19 +66,19 @@ namespace Flow.Launcher.Plugin.PluginIndicator
|
||||||
return nonGlobalPlugins;
|
return nonGlobalPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
|
||||||
{
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
|
return Localize.flowlauncher_plugin_pluginindicator_plugin_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -52,6 +53,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
|
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
|
||||||
{
|
{
|
||||||
|
internal static PluginInitContext Context { get; private set; }
|
||||||
|
|
||||||
|
private Settings _settings;
|
||||||
|
|
||||||
private readonly ProcessHelper processHelper = new();
|
private readonly ProcessHelper processHelper = new();
|
||||||
|
|
||||||
private static PluginInitContext _context;
|
|
||||||
|
|
||||||
internal Settings Settings;
|
|
||||||
|
|
||||||
private SettingsViewModel _viewModel;
|
private SettingsViewModel _viewModel;
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
Context = context;
|
||||||
Settings = context.API.LoadSettingJsonStorage<Settings>();
|
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
||||||
_viewModel = new SettingsViewModel(Settings);
|
_viewModel = new SettingsViewModel(_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
|
|
@ -31,12 +31,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return _context.API.GetTranslation("flowlauncher_plugin_processkiller_plugin_name");
|
return Localize.flowlauncher_plugin_processkiller_plugin_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
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)
|
public List<Result> LoadContextMenus(Result result)
|
||||||
|
|
@ -51,13 +51,13 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
{
|
{
|
||||||
menuOptions.Add(new Result
|
menuOptions.Add(new Result
|
||||||
{
|
{
|
||||||
Title = _context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_instances"),
|
Title = Localize.flowlauncher_plugin_processkiller_kill_instances(),
|
||||||
SubTitle = processPath,
|
SubTitle = processPath,
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
foreach (var p in similarProcesses)
|
foreach (var p in similarProcesses)
|
||||||
{
|
{
|
||||||
processHelper.TryKill(_context, p);
|
ProcessHelper.TryKill(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -72,8 +72,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
private List<Result> CreateResultsFromQuery(Query query)
|
private List<Result> CreateResultsFromQuery(Query query)
|
||||||
{
|
{
|
||||||
// Get all non-system processes
|
// Get all non-system processes
|
||||||
var allPocessList = processHelper.GetMatchingProcesses();
|
var allProcessList = processHelper.GetMatchingProcesses();
|
||||||
if (!allPocessList.Any())
|
if (allProcessList.Count == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -82,12 +82,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
var searchTerm = query.Search;
|
var searchTerm = query.Search;
|
||||||
var processlist = new List<ProcessResult>();
|
var processlist = new List<ProcessResult>();
|
||||||
var processWindowTitle =
|
var processWindowTitle =
|
||||||
Settings.ShowWindowTitle || Settings.PutVisibleWindowProcessesTop ?
|
_settings.ShowWindowTitle || _settings.PutVisibleWindowProcessesTop ?
|
||||||
ProcessHelper.GetProcessesWithNonEmptyWindowTitle() :
|
ProcessHelper.GetProcessesWithNonEmptyWindowTitle() :
|
||||||
new Dictionary<int, string>();
|
[];
|
||||||
if (string.IsNullOrWhiteSpace(searchTerm))
|
if (string.IsNullOrWhiteSpace(searchTerm))
|
||||||
{
|
{
|
||||||
foreach (var p in allPocessList)
|
foreach (var p in allProcessList)
|
||||||
{
|
{
|
||||||
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
|
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
|
||||||
|
|
||||||
|
|
@ -97,8 +97,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
// Use window title for those processes if enabled
|
// Use window title for those processes if enabled
|
||||||
processlist.Add(new ProcessResult(
|
processlist.Add(new ProcessResult(
|
||||||
p,
|
p,
|
||||||
Settings.PutVisibleWindowProcessesTop ? 200 : 0,
|
_settings.PutVisibleWindowProcessesTop ? 200 : 0,
|
||||||
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
||||||
null,
|
null,
|
||||||
progressNameIdTitle));
|
progressNameIdTitle));
|
||||||
}
|
}
|
||||||
|
|
@ -115,35 +115,35 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var p in allPocessList)
|
foreach (var p in allProcessList)
|
||||||
{
|
{
|
||||||
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
|
var progressNameIdTitle = ProcessHelper.GetProcessNameIdTitle(p);
|
||||||
|
|
||||||
if (processWindowTitle.TryGetValue(p.Id, out var windowTitle))
|
if (processWindowTitle.TryGetValue(p.Id, out var windowTitle))
|
||||||
{
|
{
|
||||||
// Get max score from searching process name, window title and process id
|
// Get max score from searching process name, window title and process id
|
||||||
var windowTitleMatch = _context.API.FuzzySearch(searchTerm, windowTitle);
|
var windowTitleMatch = Context.API.FuzzySearch(searchTerm, windowTitle);
|
||||||
var processNameIdMatch = _context.API.FuzzySearch(searchTerm, progressNameIdTitle);
|
var processNameIdMatch = Context.API.FuzzySearch(searchTerm, progressNameIdTitle);
|
||||||
var score = Math.Max(windowTitleMatch.Score, processNameIdMatch.Score);
|
var score = Math.Max(windowTitleMatch.Score, processNameIdMatch.Score);
|
||||||
if (score > 0)
|
if (score > 0)
|
||||||
{
|
{
|
||||||
// Add score to prioritize processes with visible windows
|
// Add score to prioritize processes with visible windows
|
||||||
// Use window title for those processes
|
// Use window title for those processes
|
||||||
if (Settings.PutVisibleWindowProcessesTop)
|
if (_settings.PutVisibleWindowProcessesTop)
|
||||||
{
|
{
|
||||||
score += 200;
|
score += 200;
|
||||||
}
|
}
|
||||||
processlist.Add(new ProcessResult(
|
processlist.Add(new ProcessResult(
|
||||||
p,
|
p,
|
||||||
score,
|
score,
|
||||||
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
_settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
||||||
score == windowTitleMatch.Score ? windowTitleMatch : null,
|
score == windowTitleMatch.Score ? windowTitleMatch : null,
|
||||||
progressNameIdTitle));
|
progressNameIdTitle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var processNameIdMatch = _context.API.FuzzySearch(searchTerm, progressNameIdTitle);
|
var processNameIdMatch = Context.API.FuzzySearch(searchTerm, progressNameIdTitle);
|
||||||
var score = processNameIdMatch.Score;
|
var score = processNameIdMatch.Score;
|
||||||
if (score > 0)
|
if (score > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -162,7 +162,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
foreach (var pr in processlist)
|
foreach (var pr in processlist)
|
||||||
{
|
{
|
||||||
var p = pr.Process;
|
var p = pr.Process;
|
||||||
var path = processHelper.TryGetProcessFilename(p);
|
var path = ProcessHelper.TryGetProcessFilename(p);
|
||||||
results.Add(new Result()
|
results.Add(new Result()
|
||||||
{
|
{
|
||||||
IcoPath = path,
|
IcoPath = path,
|
||||||
|
|
@ -172,12 +172,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
TitleHighlightData = pr.TitleMatch?.MatchData,
|
TitleHighlightData = pr.TitleMatch?.MatchData,
|
||||||
Score = pr.Score,
|
Score = pr.Score,
|
||||||
ContextData = p.ProcessName,
|
ContextData = p.ProcessName,
|
||||||
AutoCompleteText = $"{_context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
|
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword}{Plugin.Query.TermSeparator}{p.ProcessName}",
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
processHelper.TryKill(_context, p);
|
ProcessHelper.TryKill(p);
|
||||||
// Re-query to refresh process list
|
// Re-query to refresh process list
|
||||||
_context.API.ReQuery();
|
Context.API.ReQuery();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -194,17 +194,17 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
sortedResults.Insert(1, new Result()
|
sortedResults.Insert(1, new Result()
|
||||||
{
|
{
|
||||||
IcoPath = firstResult?.IcoPath,
|
IcoPath = firstResult?.IcoPath,
|
||||||
Title = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all"), firstResult?.ContextData),
|
Title = Localize.flowlauncher_plugin_processkiller_kill_all(firstResult?.ContextData),
|
||||||
SubTitle = string.Format(_context.API.GetTranslation("flowlauncher_plugin_processkiller_kill_all_count"), processlist.Count),
|
SubTitle = Localize.flowlauncher_plugin_processkiller_kill_all_count(processlist.Count),
|
||||||
Score = 200,
|
Score = 200,
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
foreach (var p in processlist)
|
foreach (var p in processlist)
|
||||||
{
|
{
|
||||||
processHelper.TryKill(_context, p.Process);
|
ProcessHelper.TryKill(p.Process);
|
||||||
}
|
}
|
||||||
// Re-query to refresh process list
|
// Re-query to refresh process list
|
||||||
_context.API.ReQuery();
|
Context.API.ReQuery();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
{
|
{
|
||||||
private static readonly string ClassName = nameof(ProcessHelper);
|
private static readonly string ClassName = nameof(ProcessHelper);
|
||||||
|
|
||||||
private readonly HashSet<string> _systemProcessList = new()
|
private readonly HashSet<string> _systemProcessList =
|
||||||
{
|
[
|
||||||
"conhost",
|
"conhost",
|
||||||
"svchost",
|
"svchost",
|
||||||
"idle",
|
"idle",
|
||||||
|
|
@ -31,12 +31,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
"winlogon",
|
"winlogon",
|
||||||
"services",
|
"services",
|
||||||
"spoolsv",
|
"spoolsv",
|
||||||
"explorer"
|
"explorer"
|
||||||
};
|
];
|
||||||
|
|
||||||
private const string FlowLauncherProcessName = "Flow.Launcher";
|
private const string FlowLauncherProcessName = "Flow.Launcher";
|
||||||
|
|
||||||
private bool IsSystemProcessOrFlowLauncher(Process p) =>
|
private bool IsSystemProcessOrFlowLauncher(Process p) =>
|
||||||
_systemProcessList.Contains(p.ProcessName.ToLower()) ||
|
_systemProcessList.Contains(p.ProcessName.ToLower()) ||
|
||||||
string.Equals(p.ProcessName, FlowLauncherProcessName, StringComparison.OrdinalIgnoreCase);
|
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);
|
return Process.GetProcesses().Where(p => !IsSystemProcessOrFlowLauncher(p) && TryGetProcessFilename(p) == processPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TryKill(PluginInitContext context, Process p)
|
public static void TryKill(Process p)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -154,11 +154,11 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,16 @@ using Flow.Launcher.Plugin.SharedModels;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.ProcessKiller
|
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)
|
public Process Process { get; } = process;
|
||||||
{
|
|
||||||
Process = process;
|
|
||||||
Score = score;
|
|
||||||
Title = title;
|
|
||||||
TitleMatch = match;
|
|
||||||
Tooltip = tooltip;
|
|
||||||
}
|
|
||||||
|
|
||||||
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; } = tooltip;
|
||||||
|
|
||||||
public string Tooltip { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,7 @@
|
||||||
namespace Flow.Launcher.Plugin.ProcessKiller.ViewModels
|
namespace Flow.Launcher.Plugin.ProcessKiller.ViewModels
|
||||||
{
|
{
|
||||||
public class SettingsViewModel
|
public class SettingsViewModel(Settings settings)
|
||||||
{
|
{
|
||||||
public Settings Settings { get; set; }
|
public Settings Settings { get; set; } = settings;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
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:DesignHeight="300"
|
||||||
d:DesignWidth="500"
|
d:DesignWidth="500"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
@ -18,11 +20,11 @@
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||||
Content="{DynamicResource flowlauncher_plugin_processkiller_show_window_title}"
|
Content="{DynamicResource flowlauncher_plugin_processkiller_show_window_title}"
|
||||||
IsChecked="{Binding ShowWindowTitle}" />
|
IsChecked="{Binding Settings.ShowWindowTitle}" />
|
||||||
<CheckBox
|
<CheckBox
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||||
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
|
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
|
||||||
IsChecked="{Binding PutVisibleWindowProcessesTop}" />
|
IsChecked="{Binding Settings.PutVisibleWindowProcessesTop}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
@ -5,9 +5,6 @@ namespace Flow.Launcher.Plugin.ProcessKiller.Views;
|
||||||
|
|
||||||
public partial class SettingsControl : UserControl
|
public partial class SettingsControl : UserControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Interaction logic for SettingsControl.xaml
|
|
||||||
/// </summary>
|
|
||||||
public SettingsControl(SettingsViewModel viewModel)
|
public SettingsControl(SettingsViewModel viewModel)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -58,6 +59,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
|
||||||
<PackageReference Include="InputSimulator" Version="1.0.4" NoWarn="NU1701" />
|
<PackageReference Include="InputSimulator" Version="1.0.4" NoWarn="NU1701" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Flow.Launcher.Plugin.SharedCommands;
|
||||||
using WindowsInput;
|
using WindowsInput;
|
||||||
using WindowsInput.Native;
|
using WindowsInput.Native;
|
||||||
using Flow.Launcher.Plugin.SharedCommands;
|
|
||||||
using Control = System.Windows.Controls.Control;
|
using Control = System.Windows.Controls.Control;
|
||||||
using Keys = System.Windows.Forms.Keys;
|
using Keys = System.Windows.Forms.Keys;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
private static readonly string ClassName = nameof(Main);
|
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 const string Image = "Images/shell.png";
|
||||||
private bool _winRStroked;
|
private bool _winRStroked;
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = [];
|
||||||
string cmd = query.Search;
|
string cmd = query.Search;
|
||||||
if (string.IsNullOrEmpty(cmd))
|
if (string.IsNullOrEmpty(cmd))
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
string basedir = null;
|
string basedir = null;
|
||||||
string dir = null;
|
string dir = null;
|
||||||
string excmd = Environment.ExpandEnvironmentVariables(cmd);
|
string excmd = Environment.ExpandEnvironmentVariables(cmd);
|
||||||
if (Directory.Exists(excmd) && (cmd.EndsWith("/") || cmd.EndsWith(@"\")))
|
if (Directory.Exists(excmd) && (cmd.EndsWith('/') || cmd.EndsWith('\\')))
|
||||||
{
|
{
|
||||||
basedir = excmd;
|
basedir = excmd;
|
||||||
dir = cmd;
|
dir = cmd;
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
basedir = Path.GetDirectoryName(excmd);
|
basedir = Path.GetDirectoryName(excmd);
|
||||||
var dirName = Path.GetDirectoryName(cmd);
|
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)
|
if (basedir != null)
|
||||||
|
|
@ -103,14 +103,14 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
if (m.Key == cmd)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = new Result
|
var ret = new Result
|
||||||
{
|
{
|
||||||
Title = m.Key,
|
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,
|
IcoPath = Image,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
|
|
@ -129,9 +129,9 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
}).Where(o => o != null);
|
}).Where(o => o != null);
|
||||||
|
|
||||||
if (_settings.ShowOnlyMostUsedCMDs)
|
if (_settings.ShowOnlyMostUsedCMDs)
|
||||||
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
|
return [.. history.Take(_settings.ShowOnlyMostUsedCMDsNumber)];
|
||||||
|
|
||||||
return history.ToList();
|
return [.. history];
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result GetCurrentCmd(string cmd)
|
private Result GetCurrentCmd(string cmd)
|
||||||
|
|
@ -140,7 +140,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
Title = cmd,
|
Title = cmd,
|
||||||
Score = 5000,
|
Score = 5000,
|
||||||
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_cmd_execute_through_shell"),
|
SubTitle = Localize.flowlauncher_plugin_cmd_execute_through_shell(),
|
||||||
IcoPath = Image,
|
IcoPath = Image,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
|
|
@ -165,7 +165,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
.Select(m => new Result
|
.Select(m => new Result
|
||||||
{
|
{
|
||||||
Title = m.Key,
|
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,
|
IcoPath = Image,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
|
|
@ -182,9 +182,9 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_settings.ShowOnlyMostUsedCMDs)
|
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)
|
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false)
|
||||||
|
|
@ -199,7 +199,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
Verb = runAsAdministratorArg,
|
Verb = runAsAdministratorArg,
|
||||||
WorkingDirectory = workingDirectory,
|
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 ? "\\" : "";
|
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
|
||||||
switch (_settings.Shell)
|
switch (_settings.Shell)
|
||||||
{
|
{
|
||||||
|
|
@ -288,10 +288,10 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
|
|
||||||
case Shell.RunCommand:
|
case Shell.RunCommand:
|
||||||
{
|
{
|
||||||
var parts = command.Split(new[]
|
var parts = command.Split(
|
||||||
{
|
[
|
||||||
' '
|
' '
|
||||||
}, 2);
|
], 2);
|
||||||
if (parts.Length == 2)
|
if (parts.Length == 2)
|
||||||
{
|
{
|
||||||
var filename = parts[0];
|
var filename = parts[0];
|
||||||
|
|
@ -336,12 +336,12 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
|
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)
|
catch (Win32Exception e)
|
||||||
{
|
{
|
||||||
Context.API.ShowMsgError(GetTranslatedPluginTitle(),
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -405,7 +405,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnWinRPressed()
|
private static void OnWinRPressed()
|
||||||
{
|
{
|
||||||
Context.API.ShowMainWindow();
|
Context.API.ShowMainWindow();
|
||||||
// show the main window and set focus to the query box
|
// show the main window and set focus to the query box
|
||||||
|
|
@ -428,12 +428,12 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return Context.API.GetTranslation("flowlauncher_plugin_cmd_plugin_name");
|
return Localize.flowlauncher_plugin_cmd_plugin_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
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)
|
public List<Result> LoadContextMenus(Result selectedResult)
|
||||||
|
|
@ -442,7 +442,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"),
|
Title = Localize.flowlauncher_plugin_cmd_run_as_different_user(),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title));
|
Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title));
|
||||||
|
|
@ -453,7 +453,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
},
|
},
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_administrator"),
|
Title = Localize.flowlauncher_plugin_cmd_run_as_administrator(),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
|
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
|
||||||
|
|
@ -464,7 +464,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
},
|
},
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Title = Context.API.GetTranslation("flowlauncher_plugin_cmd_copy"),
|
Title = Localize.flowlauncher_plugin_cmd_copy(),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Context.API.CopyToClipboard(selectedResult.Title);
|
Context.API.CopyToClipboard(selectedResult.Title);
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
public Shell Shell { get; set; } = Shell.Cmd;
|
public Shell Shell { get; set; } = Shell.Cmd;
|
||||||
|
|
||||||
public bool ReplaceWinR { get; set; } = false;
|
public bool ReplaceWinR { get; set; } = false;
|
||||||
|
|
||||||
public bool CloseShellAfterPress { get; set; } = false;
|
public bool CloseShellAfterPress { get; set; } = false;
|
||||||
|
|
||||||
public bool LeaveShellOpen { get; set; }
|
public bool LeaveShellOpen { get; set; }
|
||||||
|
|
||||||
public bool RunAsAdministrator { get; set; } = true;
|
public bool RunAsAdministrator { get; set; } = true;
|
||||||
|
|
@ -20,18 +20,14 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
|
|
||||||
public int ShowOnlyMostUsedCMDsNumber { get; set; }
|
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)
|
public void AddCmdHistory(string cmdName)
|
||||||
{
|
{
|
||||||
if (CommandHistory.ContainsKey(cmdName))
|
if (!CommandHistory.TryAdd(cmdName, 1))
|
||||||
{
|
{
|
||||||
CommandHistory[cmdName] += 1;
|
CommandHistory[cmdName] += 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
CommandHistory.Add(cmdName, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,18 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
|
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
|
||||||
|
|
||||||
CloseShellAfterPress.IsChecked = _settings.CloseShellAfterPress;
|
CloseShellAfterPress.IsChecked = _settings.CloseShellAfterPress;
|
||||||
|
|
||||||
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
|
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
|
||||||
|
|
||||||
AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;
|
AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;
|
||||||
|
|
||||||
UseWindowsTerminal.IsChecked = _settings.UseWindowsTerminal;
|
UseWindowsTerminal.IsChecked = _settings.UseWindowsTerminal;
|
||||||
|
|
||||||
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;
|
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;
|
||||||
|
|
||||||
ShowOnlyMostUsedCMDs.IsChecked = _settings.ShowOnlyMostUsedCMDs;
|
ShowOnlyMostUsedCMDs.IsChecked = _settings.ShowOnlyMostUsedCMDs;
|
||||||
|
|
||||||
if ((bool)!ShowOnlyMostUsedCMDs.IsChecked)
|
if (ShowOnlyMostUsedCMDs.IsChecked != true)
|
||||||
ShowOnlyMostUsedCMDsNumber.IsEnabled = false;
|
ShowOnlyMostUsedCMDsNumber.IsEnabled = false;
|
||||||
|
|
||||||
ShowOnlyMostUsedCMDsNumber.ItemsSource = new List<int>() { 5, 10, 20 };
|
ShowOnlyMostUsedCMDsNumber.ItemsSource = new List<int>() { 5, 10, 20 };
|
||||||
|
|
@ -137,7 +137,6 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
{
|
{
|
||||||
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
|
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,13 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
public partial class CommandKeywordSettingWindow
|
public partial class CommandKeywordSettingWindow
|
||||||
{
|
{
|
||||||
private readonly Command _oldSearchSource;
|
private readonly Command _oldSearchSource;
|
||||||
private readonly PluginInitContext _context;
|
|
||||||
|
|
||||||
public CommandKeywordSettingWindow(PluginInitContext context, Command old)
|
public CommandKeywordSettingWindow(Command old)
|
||||||
{
|
{
|
||||||
_context = context;
|
|
||||||
_oldSearchSource = old;
|
_oldSearchSource = old;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
CommandKeyword.Text = old.Keyword;
|
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)
|
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
|
||||||
|
|
@ -26,8 +24,8 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
var keyword = CommandKeyword.Text;
|
var keyword = CommandKeyword.Text;
|
||||||
if (string.IsNullOrEmpty(keyword))
|
if (string.IsNullOrEmpty(keyword))
|
||||||
{
|
{
|
||||||
var warning = _context.API.GetTranslation("flowlauncher_plugin_sys_input_command_keyword");
|
var warning = Localize.flowlauncher_plugin_sys_input_command_keyword();
|
||||||
_context.API.ShowMsgBox(warning);
|
Main.Context.API.ShowMsgBox(warning);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -58,6 +59,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.205">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
|
||||||
|
|
@ -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_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>
|
<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>
|
</ResourceDictionary>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Windows.Win32;
|
using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
using Windows.Win32.Foundation;
|
||||||
|
|
@ -42,7 +43,7 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
|
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
|
||||||
{"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_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,
|
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure,
|
||||||
// software updates, or other predefined reasons.
|
// 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 const string Documentation = "https://flowlauncher.com/docs/#/usage-tips";
|
||||||
|
|
||||||
private PluginInitContext _context;
|
internal static PluginInitContext Context { get; private set; }
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
private ThemeSelector _themeSelector;
|
|
||||||
private SettingsViewModel _viewModel;
|
private SettingsViewModel _viewModel;
|
||||||
|
|
||||||
public Control CreateSettingPanel()
|
public Control CreateSettingPanel()
|
||||||
{
|
{
|
||||||
UpdateLocalizedNameDescription(false);
|
UpdateLocalizedNameDescription(false);
|
||||||
return new SysSettings(_context, _viewModel);
|
return new SysSettings(_viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
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);
|
var commands = Commands(query);
|
||||||
|
|
@ -85,9 +85,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match from localized title & localized subtitle & keyword
|
// Match from localized title & localized subtitle & keyword
|
||||||
var titleMatch = _context.API.FuzzySearch(query.Search, c.Title);
|
var titleMatch = Context.API.FuzzySearch(query.Search, c.Title);
|
||||||
var subTitleMatch = _context.API.FuzzySearch(query.Search, c.SubTitle);
|
var subTitleMatch = Context.API.FuzzySearch(query.Search, c.SubTitle);
|
||||||
var keywordMatch = _context.API.FuzzySearch(query.Search, command.Keyword);
|
var keywordMatch = Context.API.FuzzySearch(query.Search, command.Keyword);
|
||||||
|
|
||||||
// Get the largest score from them
|
// Get the largest score from them
|
||||||
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
||||||
|
|
@ -113,30 +113,29 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
{
|
{
|
||||||
if (!KeywordTitleMappings.TryGetValue(key, out var translationKey))
|
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 "Title Not Found";
|
||||||
}
|
}
|
||||||
|
|
||||||
return _context.API.GetTranslation(translationKey);
|
return Context.API.GetTranslation(translationKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDescription(string key)
|
private string GetDescription(string key)
|
||||||
{
|
{
|
||||||
if (!KeywordDescriptionMappings.TryGetValue(key, out var translationKey))
|
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 "Description Not Found";
|
||||||
}
|
}
|
||||||
|
|
||||||
return _context.API.GetTranslation(translationKey);
|
return Context.API.GetTranslation(translationKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
Context = context;
|
||||||
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
||||||
_viewModel = new SettingsViewModel(_settings);
|
_viewModel = new SettingsViewModel(_settings);
|
||||||
_themeSelector = new ThemeSelector(context);
|
|
||||||
foreach (string key in KeywordTitleMappings.Keys)
|
foreach (string key in KeywordTitleMappings.Keys)
|
||||||
{
|
{
|
||||||
// Remove _cmd in the last of the strings
|
// 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 results = new List<Result>();
|
||||||
var recycleBinFolder = "shell:RecycleBinFolder";
|
var recycleBinFolder = "shell:RecycleBinFolder";
|
||||||
results.AddRange(new[]
|
results.AddRange(
|
||||||
{
|
[
|
||||||
new Result
|
new Result
|
||||||
{
|
{
|
||||||
Title = "Shutdown",
|
Title = "Shutdown",
|
||||||
|
|
@ -207,9 +206,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\shutdown.png",
|
IcoPath = "Images\\shutdown.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
var result = _context.API.ShowMsgBox(
|
var result = Context.API.ShowMsgBox(
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
|
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
|
Localize.flowlauncher_plugin_sys_shutdown_computer(),
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||||
|
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
|
|
@ -228,9 +227,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\restart.png",
|
IcoPath = "Images\\restart.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
var result = _context.API.ShowMsgBox(
|
var result = Context.API.ShowMsgBox(
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
|
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
|
Localize.flowlauncher_plugin_sys_restart_computer(),
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||||
|
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
|
|
@ -249,9 +248,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\restart_advanced.png",
|
IcoPath = "Images\\restart_advanced.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
var result = _context.API.ShowMsgBox(
|
var result = Context.API.ShowMsgBox(
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
|
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
|
Localize.flowlauncher_plugin_sys_restart_computer(),
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||||
|
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
|
|
@ -270,9 +269,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\logoff.png",
|
IcoPath = "Images\\logoff.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
var result = _context.API.ShowMsgBox(
|
var result = Context.API.ShowMsgBox(
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
|
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
|
Localize.flowlauncher_plugin_sys_log_off(),
|
||||||
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||||
|
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
|
|
@ -338,9 +337,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
var result = PInvoke.SHEmptyRecycleBin(new(), string.Empty, 0);
|
var result = PInvoke.SHEmptyRecycleBin(new(), string.Empty, 0);
|
||||||
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
|
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
|
||||||
{
|
{
|
||||||
_context.API.ShowMsgBox(
|
Context.API.ShowMsgBox(
|
||||||
string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed"), Environment.NewLine),
|
Localize.flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed(Environment.NewLine),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_error"),
|
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
|
||||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -366,7 +365,7 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe89f"),
|
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe89f"),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.HideMainWindow();
|
Context.API.HideMainWindow();
|
||||||
Application.Current.MainWindow.Close();
|
Application.Current.MainWindow.Close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -378,9 +377,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\app.png",
|
IcoPath = "Images\\app.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.SaveAppAllSettings();
|
Context.API.SaveAppAllSettings();
|
||||||
_context.API.ShowMsg(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
|
Context.API.ShowMsg(Localize.flowlauncher_plugin_sys_dlgtitle_success(),
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
|
Localize.flowlauncher_plugin_sys_dlgtext_all_settings_saved());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -391,7 +390,7 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\app.png",
|
IcoPath = "Images\\app.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.RestartApp();
|
Context.API.RestartApp();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -403,8 +402,8 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Action = c =>
|
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
|
// 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.HideMainWindow();
|
||||||
_context.API.OpenSettingDialog();
|
Context.API.OpenSettingDialog();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -416,14 +415,13 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Action = c =>
|
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.
|
// 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.ReloadAllPluginData().ContinueWith(_ =>
|
||||||
_context.API.ShowMsg(
|
Context.API.ShowMsg(
|
||||||
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
|
Localize.flowlauncher_plugin_sys_dlgtitle_success(),
|
||||||
_context.API.GetTranslation(
|
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
|
||||||
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")),
|
TaskScheduler.Current);
|
||||||
System.Threading.Tasks.TaskScheduler.Current);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -435,8 +433,8 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
IcoPath = "Images\\checkupdate.png",
|
IcoPath = "Images\\checkupdate.png",
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.HideMainWindow();
|
Context.API.HideMainWindow();
|
||||||
_context.API.CheckForNewUpdate();
|
Context.API.CheckForNewUpdate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -445,11 +443,11 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
|
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
|
||||||
Title = "Open Log Location",
|
Title = "Open Log Location",
|
||||||
IcoPath = "Images\\app.png",
|
IcoPath = "Images\\app.png",
|
||||||
CopyText = _context.API.GetLogDirectory(),
|
CopyText = Context.API.GetLogDirectory(),
|
||||||
AutoCompleteText = _context.API.GetLogDirectory(),
|
AutoCompleteText = Context.API.GetLogDirectory(),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.OpenDirectory(_context.API.GetLogDirectory());
|
Context.API.OpenDirectory(Context.API.GetLogDirectory());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -462,7 +460,7 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
AutoCompleteText = Documentation,
|
AutoCompleteText = Documentation,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.OpenUrl(Documentation);
|
Context.API.OpenUrl(Documentation);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -471,11 +469,11 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Title = "Flow Launcher UserData Folder",
|
Title = "Flow Launcher UserData Folder",
|
||||||
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
|
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
|
||||||
IcoPath = "Images\\app.png",
|
IcoPath = "Images\\app.png",
|
||||||
CopyText = _context.API.GetDataDirectory(),
|
CopyText = Context.API.GetDataDirectory(),
|
||||||
AutoCompleteText = _context.API.GetDataDirectory(),
|
AutoCompleteText = Context.API.GetDataDirectory(),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.OpenDirectory(_context.API.GetDataDirectory());
|
Context.API.OpenDirectory(Context.API.GetDataDirectory());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -486,7 +484,7 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"),
|
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.ToggleGameMode();
|
Context.API.ToggleGameMode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -499,29 +497,29 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.ActionKeyword))
|
if (string.IsNullOrEmpty(query.ActionKeyword))
|
||||||
{
|
{
|
||||||
_context.API.ChangeQuery($"{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
|
Context.API.ChangeQuery($"{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
|
||||||
}
|
}
|
||||||
else
|
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 false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
]);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_name");
|
return Localize.flowlauncher_plugin_sys_plugin_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
public string GetTranslatedPluginDescription()
|
||||||
{
|
{
|
||||||
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
|
return Localize.flowlauncher_plugin_sys_plugin_description();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCultureInfoChanged(CultureInfo _)
|
public void OnCultureInfoChanged(CultureInfo _)
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ public class Settings : BaseModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<Command> Commands { get; set; } = new ObservableCollection<Command>
|
public ObservableCollection<Command> Commands { get; set; } =
|
||||||
{
|
[
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Key = "Shutdown",
|
Key = "Shutdown",
|
||||||
|
|
@ -120,7 +120,7 @@ public class Settings : BaseModel
|
||||||
Key = "Set Flow Launcher Theme",
|
Key = "Set Flow Launcher Theme",
|
||||||
Keyword = "Set Flow Launcher Theme"
|
Keyword = "Set Flow Launcher Theme"
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Command SelectedCommand { get; set; }
|
public Command SelectedCommand { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
namespace Flow.Launcher.Plugin.Sys
|
namespace Flow.Launcher.Plugin.Sys
|
||||||
{
|
{
|
||||||
public class SettingsViewModel
|
public class SettingsViewModel(Settings settings)
|
||||||
{
|
{
|
||||||
public SettingsViewModel(Settings settings)
|
public Settings Settings { get; } = settings;
|
||||||
{
|
|
||||||
Settings = settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Settings Settings { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Sys
|
namespace Flow.Launcher.Plugin.Sys
|
||||||
{
|
{
|
||||||
public partial class SysSettings : UserControl
|
public partial class SysSettings : UserControl
|
||||||
{
|
{
|
||||||
private readonly PluginInitContext _context;
|
|
||||||
private readonly Settings _settings;
|
private readonly Settings _settings;
|
||||||
|
|
||||||
public SysSettings(PluginInitContext context, SettingsViewModel viewModel)
|
public SysSettings(SettingsViewModel viewModel)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_context = context;
|
|
||||||
_settings = viewModel.Settings;
|
_settings = viewModel.Settings;
|
||||||
DataContext = viewModel;
|
DataContext = viewModel;
|
||||||
}
|
}
|
||||||
|
|
@ -37,15 +36,15 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
|
|
||||||
public void OnEditCommandKeywordClick(object sender, RoutedEventArgs e)
|
public void OnEditCommandKeywordClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var commandKeyword = new CommandKeywordSettingWindow(_context, _settings.SelectedCommand);
|
var commandKeyword = new CommandKeywordSettingWindow(_settings.SelectedCommand);
|
||||||
commandKeyword.ShowDialog();
|
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)
|
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();
|
commandKeyword.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,40 +4,30 @@ using Flow.Launcher.Plugin.SharedModels;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Sys
|
namespace Flow.Launcher.Plugin.Sys
|
||||||
{
|
{
|
||||||
public class ThemeSelector
|
public static class ThemeSelector
|
||||||
{
|
{
|
||||||
public const string Keyword = "fltheme";
|
public const string Keyword = "fltheme";
|
||||||
|
|
||||||
private readonly PluginInitContext _context;
|
public static List<Result> Query(Query query)
|
||||||
|
|
||||||
public ThemeSelector(PluginInitContext context)
|
|
||||||
{
|
{
|
||||||
_context = context;
|
var themes = Main.Context.API.GetAvailableThemes();
|
||||||
}
|
var selectedTheme = Main.Context.API.GetCurrentTheme();
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
|
||||||
{
|
|
||||||
var themes = _context.API.GetAvailableThemes();
|
|
||||||
var selectedTheme = _context.API.GetCurrentTheme();
|
|
||||||
|
|
||||||
var search = query.SecondToEndSearch;
|
var search = query.SecondToEndSearch;
|
||||||
if (string.IsNullOrWhiteSpace(search))
|
if (string.IsNullOrWhiteSpace(search))
|
||||||
{
|
{
|
||||||
return themes.Select(x => CreateThemeResult(x, selectedTheme))
|
return [.. themes.Select(x => CreateThemeResult(x, selectedTheme)).OrderBy(x => x.Title)];
|
||||||
.OrderBy(x => x.Title)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name)))
|
return [.. themes.Select(theme => (theme, matchResult: Main.Context.API.FuzzySearch(search, theme.Name)))
|
||||||
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
|
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
|
||||||
.Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData))
|
.Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData))
|
||||||
.OrderBy(x => x.Title)
|
.OrderBy(x => x.Title)];
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
string title;
|
||||||
if (theme == selectedTheme)
|
if (theme == selectedTheme)
|
||||||
|
|
@ -53,17 +43,28 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
score = 1000;
|
score = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
string description = string.Empty;
|
string description;
|
||||||
if (theme.IsDark == true)
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (theme.HasBlur == true)
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(description))
|
if (theme.HasBlur == true)
|
||||||
description += " ";
|
{
|
||||||
description += _context.API.GetTranslation("TypeHasBlurToolTip");
|
description = Localize.flowlauncher_plugin_sys_type_hasblur();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
description = string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Result
|
return new Result
|
||||||
|
|
@ -76,9 +77,9 @@ namespace Flow.Launcher.Plugin.Sys
|
||||||
Score = score,
|
Score = score,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
if (_context.API.SetCurrentTheme(theme))
|
if (Main.Context.API.SetCurrentTheme(theme))
|
||||||
{
|
{
|
||||||
_context.API.ReQuery();
|
Main.Context.API.ReQuery();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
<NoWarn>$(NoWarn);FLSG0007</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -56,4 +57,8 @@
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
"(?:/\\S*)?" +
|
"(?:/\\S*)?" +
|
||||||
"$";
|
"$";
|
||||||
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
private PluginInitContext context;
|
internal static PluginInitContext Context { get; private set; }
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
new Result
|
new Result
|
||||||
{
|
{
|
||||||
Title = raw,
|
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",
|
IcoPath = "Images/url.png",
|
||||||
Score = 8,
|
Score = 8,
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
|
|
@ -64,13 +64,13 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context.API.OpenUrl(raw);
|
Context.API.OpenUrl(raw);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(Exception)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,19 +99,19 @@ namespace Flow.Launcher.Plugin.Url
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
Context = context;
|
||||||
|
|
||||||
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("flowlauncher_plugin_url_plugin_name");
|
return Localize.flowlauncher_plugin_url_plugin_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
public string GetTranslatedPluginDescription()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("flowlauncher_plugin_url_plugin_description");
|
return Localize.flowlauncher_plugin_url_plugin_description();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue