From 44ac1c1fb59c1fdae553f8789a12fcca332cca97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Thu, 12 Feb 2026 19:39:00 +0100 Subject: [PATCH] Remove redundant code --- .../Commands/SwitchToWindowCommand.cs | 15 ++++++--------- .../Components/ContextMenuHelper.cs | 4 ++-- .../Helpers/CVirtualDesktopManager.cs | 4 +--- .../Pages/WindowWalkerListPage.cs | 10 +++++----- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs index 611c32fd2d..ae7693d8ca 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/SwitchToWindowCommand.cs @@ -57,16 +57,13 @@ internal sealed partial class SwitchToWindowCommand : InvokableCommand else { var p = Process.GetProcessById((int)_window.Process.ProcessID); - if (p is not null) + try + { + var processFileName = p.MainModule?.FileName; + Icon = new IconInfo(processFileName); + } + catch { - try - { - var processFileName = p.MainModule?.FileName; - Icon = new IconInfo(processFileName); - } - catch - { - } } } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs index b285b5bfd8..a166b8fa82 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs @@ -25,7 +25,7 @@ internal static class ContextMenuHelper { new(new CloseWindowCommand(windowData)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(true, false, false, false, (int)VirtualKey.F4, 0), + RequestedShortcut = KeyChordHelpers.FromModifiers(true, false, false, false, (int)VirtualKey.F4), }, }; @@ -36,7 +36,7 @@ internal static class ContextMenuHelper { contextMenu.Add(new CommandContextItem(new EndTaskCommand(windowData)) { - RequestedShortcut = KeyChordHelpers.FromModifiers(true, false, false, false, (int)VirtualKey.Delete, 0), + RequestedShortcut = KeyChordHelpers.FromModifiers(true, false, false, false, (int)VirtualKey.Delete), IsCritical = true, }); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/CVirtualDesktopManager.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/CVirtualDesktopManager.cs index 26663dd5f0..5ae9941883 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/CVirtualDesktopManager.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/CVirtualDesktopManager.cs @@ -12,6 +12,4 @@ namespace Microsoft.CmdPal.Ext.WindowWalker.Helpers; /// [ComImport] [Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a")] -internal class CVirtualDesktopManager -{ -} +internal class CVirtualDesktopManager; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListPage.cs index b9531163f9..1fafbe63c5 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Pages/WindowWalkerListPage.cs @@ -41,8 +41,8 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl { ArgumentNullException.ThrowIfNull(query); - _cancellationTokenSource?.Cancel(); - _cancellationTokenSource?.Dispose(); + _cancellationTokenSource.Cancel(); + _cancellationTokenSource.Dispose(); _cancellationTokenSource = new System.Threading.CancellationTokenSource(); WindowWalkerCommandsProvider.VirtualDesktopHelperInstance.UpdateDesktopList(); @@ -54,7 +54,7 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl { if (!SettingsManager.Instance.InMruOrder) { - windows.Sort(static (a, b) => string.Compare(a?.Title, b?.Title, StringComparison.OrdinalIgnoreCase)); + windows.Sort(static (a, b) => string.Compare(a.Title, b.Title, StringComparison.OrdinalIgnoreCase)); } var results = new Scored[windows.Count]; @@ -73,7 +73,7 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl private static int ScoreFunction(string q, Window window) { var titleScore = FuzzyStringMatcher.ScoreFuzzy(q, window.Title); - var processNameScore = FuzzyStringMatcher.ScoreFuzzy(q, window.Process?.Name ?? string.Empty); + var processNameScore = FuzzyStringMatcher.ScoreFuzzy(q, window.Process.Name ?? string.Empty); return Math.Max(titleScore, processNameScore); } @@ -91,7 +91,7 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl { if (disposing) { - _cancellationTokenSource?.Dispose(); + _cancellationTokenSource.Dispose(); _disposed = true; } }