From 26c946c931dff7fc248bfb2403e298127c6e143a 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:47:11 +0100 Subject: [PATCH] Remove redundant code --- .../Components/ContextMenuHelper.cs | 5 ++- .../Components/OpenWindows.cs | 2 +- .../Components/ResultHelper.cs | 4 --- .../Components/Window.cs | 34 +++++++++---------- 4 files changed, 22 insertions(+), 23 deletions(-) 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 a166b8fa82..08f64af3ac 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 @@ -16,11 +16,14 @@ internal static class ContextMenuHelper { internal static List GetContextMenuResults(in WindowWalkerListItem listItem) { - if (listItem?.Window is not Window windowData) + ArgumentNullException.ThrowIfNull(listItem); + + if (listItem.Window is null) { return []; } + var windowData = listItem.Window; var contextMenu = new List { new(new CloseWindowCommand(windowData)) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/OpenWindows.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/OpenWindows.cs index 2abc5461be..df84002a71 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/OpenWindows.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/OpenWindows.cs @@ -98,7 +98,7 @@ internal sealed class OpenWindows /// Value being passed from the caller (we don't use this but might come in handy /// in the future /// true to make sure to continue enumeration - internal bool WindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam) + private bool WindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam) { var tokenHandle = GCHandle.FromIntPtr(lParam); var target = (CancellationToken?)tokenHandle.Target ?? CancellationToken.None; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs index fe50ab370b..486f46c9bb 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ResultHelper.cs @@ -35,10 +35,6 @@ internal static class ResultHelper for (var i = 0; i < list.Count; i++) { var window = list[i].Item; - if (window?.Process is null) - { - continue; - } if (string.Equals(window.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) && window.Process.IsShellProcess) { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/Window.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/Window.cs index d0b1b0293b..32174c964a 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/Window.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/Window.cs @@ -115,7 +115,7 @@ internal sealed class Window /// /// Gets a value indicating whether the window is minimized /// - internal bool Minimized => GetWindowSizeState() == WindowSizeState.Minimized; + private bool Minimized => GetWindowSizeState() == WindowSizeState.Minimized; /// /// Initializes a new instance of the class. @@ -159,7 +159,7 @@ internal sealed class Window /// /// Helper function to close the window /// - internal void CloseThisWindowHelper() + private void CloseThisWindowHelper() { _ = NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_SYSCOMMAND, Win32Constants.SC_CLOSE, 0, 0x0000, 5000, out _); } @@ -169,7 +169,7 @@ internal sealed class Window /// internal void CloseThisWindow() { - Thread thread = new(new ThreadStart(CloseThisWindowHelper)); + Thread thread = new(CloseThisWindowHelper); thread.Start(); } @@ -188,24 +188,24 @@ internal sealed class Window } // Try WM_GETICON with SendMessageTimeout - if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_BIG, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out var result) != 0 && result != 0) + if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_BIG, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out var result) != 0 && result != 0) { - icon = System.Drawing.Icon.FromHandle((IntPtr)result); - NativeMethods.DestroyIcon((IntPtr)result); + icon = System.Drawing.Icon.FromHandle(result); + NativeMethods.DestroyIcon(result); return true; } - if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_SMALL, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0) + if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_SMALL, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0) { - icon = System.Drawing.Icon.FromHandle((IntPtr)result); - NativeMethods.DestroyIcon((IntPtr)result); + icon = System.Drawing.Icon.FromHandle(result); + NativeMethods.DestroyIcon(result); return true; } - if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, (UIntPtr)Win32Constants.ICON_SMALL2, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0) + if (NativeMethods.SendMessageTimeout(Hwnd, Win32Constants.WM_GETICON, Win32Constants.ICON_SMALL2, IntPtr.Zero, Win32Constants.SMTO_ABORTIFHUNG, 100, out result) != 0 && result != 0) { - icon = System.Drawing.Icon.FromHandle((IntPtr)result); - NativeMethods.DestroyIcon((IntPtr)result); + icon = System.Drawing.Icon.FromHandle(result); + NativeMethods.DestroyIcon(result); return true; } @@ -214,7 +214,7 @@ internal sealed class Window if (iconHandle != IntPtr.Zero) { icon = System.Drawing.Icon.FromHandle(iconHandle); - NativeMethods.DestroyIcon((IntPtr)iconHandle); + NativeMethods.DestroyIcon(iconHandle); return true; } @@ -222,7 +222,7 @@ internal sealed class Window if (iconHandle != IntPtr.Zero) { icon = System.Drawing.Icon.FromHandle(iconHandle); - NativeMethods.DestroyIcon((IntPtr)iconHandle); + NativeMethods.DestroyIcon(iconHandle); return true; } @@ -242,8 +242,8 @@ internal sealed class Window /// /// Returns what the window size is /// - /// The state (minimized, maximized, etc..) of the window - internal WindowSizeState GetWindowSizeState() + /// The state (minimized, maximized, etc...) of the window + private WindowSizeState GetWindowSizeState() { NativeMethods.GetWindowPlacement(Hwnd, out var placement); @@ -369,7 +369,7 @@ internal sealed class Window { new Task(() => { - var callbackptr = new EnumWindowsProc((IntPtr hwnd, IntPtr lParam) => + var callbackptr = new EnumWindowsProc((hwnd, _) => { // Every uwp app main window has at least three child windows. Only the one we are interested in has a class starting with "Windows.UI.Core." and is assigned to the real app process. // (The other ones have a class name that begins with the string "ApplicationFrame".)