mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[PT Run] Services plugin: Various improvements (#17985)
* search for contains too * fix startup types & new filter * fix spelling * small fixes * fix spacing * Improve order and layout * clean up * switch to nullable int32
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -122,6 +122,7 @@ autogenerated
|
|||||||
AUTOHIDE
|
AUTOHIDE
|
||||||
AUTOMATIONPROPERTIES
|
AUTOMATIONPROPERTIES
|
||||||
Autorun
|
Autorun
|
||||||
|
Autostart
|
||||||
AUTOUPDATE
|
AUTOUPDATE
|
||||||
AValid
|
AValid
|
||||||
Avanc
|
Avanc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Reflection;
|
|||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
|
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
|
||||||
|
using Microsoft.Win32;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Plugin.Logger;
|
using Wox.Plugin.Logger;
|
||||||
@@ -21,11 +22,30 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
{
|
{
|
||||||
public static IEnumerable<Result> Search(string search, string icoPath, PluginInitContext context)
|
public static IEnumerable<Result> Search(string search, string icoPath, PluginInitContext context)
|
||||||
{
|
{
|
||||||
var services = ServiceController.GetServices();
|
var services = ServiceController.GetServices().OrderBy(s => s.DisplayName);
|
||||||
|
IEnumerable<ServiceController> serviceList = new List<ServiceController>();
|
||||||
|
|
||||||
return services
|
if (search.StartsWith(Resources.wox_plugin_service_status + ":", StringComparison.CurrentCultureIgnoreCase))
|
||||||
.Where(s => s.DisplayName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || GetResultTitle(s).StartsWith(search, StringComparison.OrdinalIgnoreCase))
|
{
|
||||||
.Select(s =>
|
// allows queries like 'status:running'
|
||||||
|
serviceList = services.Where(s => GetLocalizedStatus(s.Status).Contains(search.Split(':')[1], StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
else if (search.StartsWith(Resources.wox_plugin_service_startup + ":", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
// allows queries like 'startup:automatic'
|
||||||
|
serviceList = services.Where(s => GetLocalizedStartType(s.StartType, s.ServiceName).Contains(search.Split(':')[1], StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// To show 'starts with' results first, we split the search into two steps and then concatenating the lists.
|
||||||
|
var servicesStartsWith = services
|
||||||
|
.Where(s => s.DisplayName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.StartsWith(search, StringComparison.OrdinalIgnoreCase));
|
||||||
|
var servicesContains = services.Except(servicesStartsWith)
|
||||||
|
.Where(s => s.DisplayName.Contains(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.Contains(search, StringComparison.OrdinalIgnoreCase));
|
||||||
|
serviceList = servicesStartsWith.Concat(servicesContains);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceList.Select(s =>
|
||||||
{
|
{
|
||||||
ServiceResult serviceResult = new ServiceResult(s);
|
ServiceResult serviceResult = new ServiceResult(s);
|
||||||
Func<ActionContext, bool> serviceAction;
|
Func<ActionContext, bool> serviceAction;
|
||||||
@@ -48,8 +68,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
|
|
||||||
return new Result
|
return new Result
|
||||||
{
|
{
|
||||||
Title = ServiceHelper.GetResultTitle(s),
|
Title = s.DisplayName,
|
||||||
SubTitle = ServiceHelper.GetResultSubTitle(s),
|
SubTitle = ServiceHelper.GetResultSubTitle(s),
|
||||||
|
ToolTipData = new ToolTipData(serviceResult.DisplayName, serviceResult.ServiceName),
|
||||||
IcoPath = icoPath,
|
IcoPath = icoPath,
|
||||||
ContextData = serviceResult,
|
ContextData = serviceResult,
|
||||||
Action = serviceAction,
|
Action = serviceAction,
|
||||||
@@ -118,17 +139,6 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
Helper.OpenInShell("services.msc");
|
Helper.OpenInShell("services.msc");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetResultTitle(ServiceController serviceController)
|
|
||||||
{
|
|
||||||
if (serviceController == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(serviceController));
|
|
||||||
}
|
|
||||||
|
|
||||||
var suffix = $"({serviceController.ServiceName})";
|
|
||||||
return serviceController.DisplayName.EndsWith(suffix, StringComparison.CurrentCulture) ? serviceController.DisplayName : $"{serviceController.DisplayName} {suffix}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetResultSubTitle(ServiceController serviceController)
|
private static string GetResultSubTitle(ServiceController serviceController)
|
||||||
{
|
{
|
||||||
if (serviceController == null)
|
if (serviceController == null)
|
||||||
@@ -136,7 +146,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
throw new ArgumentNullException(nameof(serviceController));
|
throw new ArgumentNullException(nameof(serviceController));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{Resources.wox_plugin_service_status}: {GetLocalizedStatus(serviceController.Status)} - {Resources.wox_plugin_service_startup}: {GetLocalizedStartType(serviceController.StartType)}";
|
return $"{Resources.wox_plugin_service_status}: {GetLocalizedStatus(serviceController.Status)} - {Resources.wox_plugin_service_startup}: {GetLocalizedStartType(serviceController.StartType, serviceController.ServiceName)} - {Resources.wox_plugin_service_name}: {serviceController.ServiceName}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetLocalizedStatus(ServiceControllerStatus status)
|
private static string GetLocalizedStatus(ServiceControllerStatus status)
|
||||||
@@ -175,7 +185,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetLocalizedStartType(ServiceStartMode startMode)
|
private static string GetLocalizedStartType(ServiceStartMode startMode, string serviceName)
|
||||||
{
|
{
|
||||||
if (startMode == ServiceStartMode.Boot)
|
if (startMode == ServiceStartMode.Boot)
|
||||||
{
|
{
|
||||||
@@ -187,7 +197,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
}
|
}
|
||||||
else if (startMode == ServiceStartMode.Automatic)
|
else if (startMode == ServiceStartMode.Automatic)
|
||||||
{
|
{
|
||||||
return Resources.wox_plugin_service_start_mode_automatic;
|
return !IsDelayedStart(serviceName) ? Resources.wox_plugin_service_start_mode_automatic : Resources.wox_plugin_service_start_mode_automaticDelayed;
|
||||||
}
|
}
|
||||||
else if (startMode == ServiceStartMode.Manual)
|
else if (startMode == ServiceStartMode.Manual)
|
||||||
{
|
{
|
||||||
@@ -242,5 +252,10 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsDelayedStart(string serviceName)
|
||||||
|
{
|
||||||
|
return (int?)Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services\" + serviceName, false)?.GetValue("DelayedAutostart", 0, RegistryValueOptions.None) == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources {
|
||||||
@@ -69,6 +69,15 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Name.
|
||||||
|
/// </summary>
|
||||||
|
internal static string wox_plugin_service_name {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_service_name", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Open services (Ctrl+O).
|
/// Looks up a localized string similar to Open services (Ctrl+O).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -177,6 +186,15 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Automatic (Delayed Start).
|
||||||
|
/// </summary>
|
||||||
|
internal static string wox_plugin_service_start_mode_automaticDelayed {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_service_start_mode_automaticDelayed", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Boot.
|
/// Looks up a localized string similar to Boot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -120,6 +120,9 @@
|
|||||||
<data name="wox_plugin_service_continue_pending" xml:space="preserve">
|
<data name="wox_plugin_service_continue_pending" xml:space="preserve">
|
||||||
<value>Continue</value>
|
<value>Continue</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="wox_plugin_service_name" xml:space="preserve">
|
||||||
|
<value>Name</value>
|
||||||
|
</data>
|
||||||
<data name="wox_plugin_service_open_services" xml:space="preserve">
|
<data name="wox_plugin_service_open_services" xml:space="preserve">
|
||||||
<value>Open services (Ctrl+O)</value>
|
<value>Open services (Ctrl+O)</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -165,6 +168,9 @@
|
|||||||
<data name="wox_plugin_service_start_mode_automatic" xml:space="preserve">
|
<data name="wox_plugin_service_start_mode_automatic" xml:space="preserve">
|
||||||
<value>Automatic</value>
|
<value>Automatic</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="wox_plugin_service_start_mode_automaticDelayed" xml:space="preserve">
|
||||||
|
<value>Automatic (Delayed Start)</value>
|
||||||
|
</data>
|
||||||
<data name="wox_plugin_service_start_mode_boot" xml:space="preserve">
|
<data name="wox_plugin_service_start_mode_boot" xml:space="preserve">
|
||||||
<value>Boot</value>
|
<value>Boot</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user