mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
## Summary of the Pull Request Ensures the Command Palette main window stays hidden from the taskbar after Windows Explorer restarts. Also updates how app switcher visibility is managed to prevent unhandled exceptions and avoid startup crashes when Explorer is not running or is not responsive. ## PR Checklist - [x] Closes: #40334 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** no tests - [x] **Localization:** nothing to localize - [x] **Dev docs:** nothing to update - [x] **New binaries:** no new binaries - [x] **Documentation updated:** nothing to update ## Detailed Description of the Pull Request / Additional comments - Settings on the main window are reapplied after the taskbar is re-created (e.g., after Windows Explorer restarts), restoring visibility settings for the app switcher and taskbar button. - Defensive handling of the property AppWindow.IsShownInSwitchers controlling appearance in system representations such as ALT+TAB and the taskbar, to avoid errors when Windows Explorer is not running (see https://github.com/microsoft/microsoft-ui-xaml/issues/8596). - Prevents application startup failures when the Command Palette is launched in environments without Windows Explorer. ## Validation Steps Performed - Verified that the CmdPal main window taskbar button is not visible after Explorer is restarted (without an attached debugger). - Verified that CmdPal can be started when Explorer is not running. - Verified that the CmdPal main window taskbar button is visible after Explorer is restarted (if a debugger is attached to CmdPal).
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
// 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 Microsoft.UI;
|
|
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
|
|
namespace Microsoft.CmdPal.UI.Helpers;
|
|
|
|
public static class WindowExtensions
|
|
{
|
|
public static void SetIcon(this Window window)
|
|
{
|
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
|
|
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
|
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
|
appWindow.SetIcon(@"Assets\icon.ico");
|
|
}
|
|
|
|
public static void SetVisibilityInSwitchers(this Window window, bool showInSwitchers)
|
|
{
|
|
try
|
|
{
|
|
// IsShownInSwitchers needs to change the value to apply the effect, but its state might be out-of-sync with
|
|
// the actual state of the switchers, so we need to toggle it.
|
|
window.AppWindow.IsShownInSwitchers = !showInSwitchers;
|
|
window.AppWindow.IsShownInSwitchers = showInSwitchers;
|
|
}
|
|
catch (NotImplementedException)
|
|
{
|
|
// SetShownInSwitchers failed. This can happen if the Explorer is not running.
|
|
}
|
|
}
|
|
}
|