diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinCommand.cs index 932e421e42..a62dd720b9 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinCommand.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.CmdPal.Ext.System.Helpers; using Microsoft.CommandPalette.Extensions.Toolkit; -namespace Microsoft.CmdPal.Ext.Shell; +namespace Microsoft.CmdPal.Ext.System; public sealed partial class EmptyRecycleBinCommand : InvokableCommand { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinConfirmation.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinConfirmation.cs index c15247d8cb..558cd6b893 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinConfirmation.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinConfirmation.cs @@ -2,7 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CmdPal.Ext.Shell; using Microsoft.CmdPal.Ext.System.Helpers; using Microsoft.CommandPalette.Extensions.Toolkit; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/FallbackSystemCommandItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/FallbackSystemCommandItem.cs new file mode 100644 index 0000000000..94b23e3e0d --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/FallbackSystemCommandItem.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using Microsoft.CmdPal.Ext.System.Helpers; +using Microsoft.CommandPalette.Extensions; +using Microsoft.CommandPalette.Extensions.Toolkit; + +namespace Microsoft.CmdPal.Ext.System; + +internal sealed partial class FallbackSystemCommandItem : FallbackCommandItem +{ + public FallbackSystemCommandItem(SettingsManager settings) + : base(new NoOpCommand(), Resources.Microsoft_plugin_ext_fallback_display_title) + { + Title = string.Empty; + Subtitle = string.Empty; + + var isBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi; + var hideEmptyRB = settings.HideEmptyRecycleBin; + var confirmSystemCommands = settings.ShowDialogToConfirmCommand; + var showSuccessOnEmptyRB = settings.ShowSuccessMessageAfterEmptyingRecycleBin; + + systemCommands = Commands.GetSystemCommands(isBootedInUefiMode, hideEmptyRB, confirmSystemCommands, showSuccessOnEmptyRB); + } + + private readonly List systemCommands; + + public override void UpdateQuery(string query) + { + if (string.IsNullOrWhiteSpace(query)) + { + Title = string.Empty; + Subtitle = string.Empty; + return; + } + + IListItem? result = null; + var resultScore = 0; + + // find the max score for the query + foreach (var command in systemCommands) + { + var title = command.Title; + var subTitle = command.Subtitle; + var titleScore = StringMatcher.FuzzySearch(query, title).Score; + var subTitleScore = StringMatcher.FuzzySearch(query, subTitle).Score; + + var maxScore = Math.Max(titleScore, subTitleScore); + if (maxScore > resultScore) + { + resultScore = maxScore; + result = command; + } + } + + if (result == null) + { + Title = string.Empty; + Subtitle = string.Empty; + + return; + } + + Title = result.Title; + Subtitle = result.Subtitle; + Icon = result.Icon; + Command = result.Command; + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.Designer.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.Designer.cs index 6aa26a7b0d..1574a2aa0d 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.Designer.cs @@ -186,6 +186,15 @@ namespace Microsoft.CmdPal.Ext.System { } } + /// + /// Looks up a localized string similar to Open System Command. + /// + public static string Microsoft_plugin_ext_fallback_display_title { + get { + return ResourceManager.GetString("Microsoft_plugin_ext_fallback_display_title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Hide disconnected network info. /// diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx index e71e8a8d01..0aaa3d0611 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx @@ -411,4 +411,7 @@ Sleep + + Open System Command + \ No newline at end of file diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandExtensionProvider.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandExtensionProvider.cs index be89cf75fd..b1dc3ffc26 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandExtensionProvider.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandExtensionProvider.cs @@ -14,6 +14,7 @@ public partial class SystemCommandExtensionProvider : CommandProvider private readonly ICommandItem[] _commands; private static readonly SettingsManager _settingsManager = new(); public static readonly SystemCommandPage Page = new(_settingsManager); + private readonly FallbackSystemCommandItem _fallbackFileItem = new(_settingsManager); public SystemCommandExtensionProvider() { @@ -36,4 +37,6 @@ public partial class SystemCommandExtensionProvider : CommandProvider { return _commands; } + + public override IFallbackCommandItem[] FallbackCommands() => [_fallbackFileItem]; } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandsCache.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandsCache.cs deleted file mode 100644 index a2a61b2b50..0000000000 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/SystemCommandsCache.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.CmdPal.Ext.System.Helpers; -using Microsoft.CommandPalette.Extensions; - -namespace Microsoft.CmdPal.Ext.System; - -public sealed partial class SystemCommandsCache -{ - public SystemCommandsCache(SettingsManager manager) - { - var list = new List(); - var listLock = new object(); - - var a = Task.Run(() => - { - var isBootedInUefiMode = Win32Helpers.GetSystemFirmwareType() == FirmwareType.Uefi; - - var separateEmptyRB = manager.HideEmptyRecycleBin; - var confirmSystemCommands = manager.ShowDialogToConfirmCommand; - var showSuccessOnEmptyRB = manager.ShowSuccessMessageAfterEmptyingRecycleBin; - - // normal system commands are fast and can be returned immediately - var systemCommands = Commands.GetSystemCommands(isBootedInUefiMode, separateEmptyRB, confirmSystemCommands, showSuccessOnEmptyRB); - lock (listLock) - { - list.AddRange(systemCommands); - } - }); - - var b = Task.Run(() => - { - // Network (ip and mac) results are slow with many network cards and returned delayed. - // On global queries the first word/part has to be 'ip', 'mac' or 'address' for network results - var networkConnectionResults = Commands.GetNetworkConnectionResults(manager); - lock (listLock) - { - list.AddRange(networkConnectionResults); - } - }); - - Task.WaitAll(a, b); - CachedCommands = list.ToArray(); - } - - public IListItem[] CachedCommands { get; } -}