Skip to content

Conversation

@ThanhNguyxn
Copy link

@ThanhNguyxn ThanhNguyxn commented Dec 3, 2025

Summary of the Pull Request

Fixes the "Stay open after closing windows and killing processes" setting not working for the "Close Window" command in Window Walker (Command Palette).

PR Checklist

Problem

The "Stay open after closing windows and killing processes" setting (OpenAfterKillAndClose) was being respected by the "End Task" command but not by the "Close Window" command.

  • "End Task" → Command Palette stays open ✅
  • "Close Window" → Command Palette closes ❌ (should stay open)

Solution

Updated CloseWindowCommand.Invoke() to check the SettingsManager.Instance.OpenAfterKillAndClose setting and return CommandResult.KeepOpen() or CommandResult.Dismiss() accordingly, matching the behavior of EndTaskCommand.

// Before:
return CommandResult.Dismiss();

// After:
return SettingsManager.Instance.OpenAfterKillAndClose ? CommandResult.KeepOpen() : CommandResult.Dismiss();

Validation Steps Performed

  1. Enable "Stay open after closing windows and killing processes" in Window Walker settings
  2. Open Command Palette and search for a window
  3. Use "Close Window" command → Command Palette now stays open ✅
  4. Use "End Task" command → Command Palette stays open (unchanged) ✅

Copilot AI review requested due to automatic review settings December 3, 2025 03:19
@ThanhNguyxn
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a settings inconsistency where the "Stay open after closing windows and killing processes" setting (OpenAfterKillAndClose) was not being respected by the "Close Window" command in Window Walker. The fix aligns CloseWindowCommand with EndTaskCommand's behavior by checking the setting and returning the appropriate CommandResult.

Key Changes:

  • Added SettingsManager.Instance check to CloseWindowCommand.Invoke() to respect the OpenAfterKillAndClose setting
  • Added necessary using directive for Microsoft.CmdPal.Ext.WindowWalker.Helpers

@jiripolasek jiripolasek added the Product-Command Palette Refers to the Command Palette utility label Dec 3, 2025
@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jiripolasek
Copy link
Collaborator

🟠 I think this could use a bit more polish. It fixes the immediate issue, but doesn’t refresh the list, so closing the window leaves the list unchanged, which can be confusing.

@ThanhNguyxn
Copy link
Author

@jiripolasek Thanks for the feedback! You're right that the list doesn't refresh after closing the window.

I see a few approaches to address this:

  1. Have the command trigger a list refresh - The CloseWindowCommand would need a reference to WindowWalkerListPage to call RaiseItemsChanged(). This would require passing the page reference when creating the command, or using some form of event/delegate pattern.

  2. Use a timer-based refresh - Add a short delay after CloseThisWindow() before refreshing, allowing Windows time to actually close the window. This seems hacky though.

  3. Use a file system watcher / window hook pattern - Monitor when windows are closed and refresh accordingly. This is more complex.

Could you suggest which approach would be preferred for this extension, or if there's an existing pattern in Command Palette extensions that handles this scenario? I want to make sure the solution aligns with the codebase conventions.

Looking at EndTaskCommand, it has the same limitation - when KeepOpen() is returned, the list also doesn't refresh after the process is killed. Should this PR address both commands, or should this be a separate issue for the broader "refresh list after action" behavior?

zadjii-msft
zadjii-msft previously approved these changes Dec 3, 2025
@zadjii-msft zadjii-msft dismissed their stale review December 3, 2025 12:48

derp I didn't read the thread. JIri's got a good point

@ThanhNguyxn ThanhNguyxn force-pushed the fix/cmdpal-window-walker-stay-open branch from 27b3622 to 01f6aa8 Compare December 3, 2025 12:52
@zadjii-msft
Copy link
Member

Hmmm. The event seems like it's the most correct, but that's kind of a lot of plumbing, based on the way the WindowWalkerListPage is separated from the ResultHelper from the ContextMenuHelper.

Honestly, the easiest solution would be to add a weak reference messenger (need to add a dependency to WW project), send a "RefreshWindows" message from the close command, and handle that up on the list page.

@ThanhNguyxn
Copy link
Author

@zadjii-msft Thanks for the guidance! I've implemented the WeakReferenceMessenger approach.

Changes:

  1. Added CommunityToolkit.Mvvm dependency to the WindowWalker project
  2. Created RefreshWindowsMessage in new Messages/ folder
  3. Updated both CloseWindowCommand and EndTaskCommand to send the message when KeepOpen() is returned
  4. WindowWalkerListPage now implements IRecipient<RefreshWindowsMessage> and calls RaiseItemsChanged(0) to refresh the list
  5. Added a small 100ms delay before refresh to give Windows time to actually close the window
  6. Properly unregisters the messenger in Dispose()

This should now refresh the window list after closing a window or killing a process when the "Stay open" setting is enabled. Please re-test when you get a chance!

@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jiripolasek
Copy link
Collaborator

@ThanhNguyxn It’s not compiling:

src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.WindowWalker\Commands\EndTaskCommand.cs(34,204): Error CS0103: The name 'StringComparison' does not exist in the current context

@ThanhNguyxn
Copy link
Author

@jiripolasek Fixed! Added the missing using System; for StringComparison in commit 41b7e91.

Please trigger CI again when you have a chance. 🙏

@ThanhNguyxn ThanhNguyxn force-pushed the fix/cmdpal-window-walker-stay-open branch from 41b7e91 to 661c0e4 Compare December 4, 2025 01:07
@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ThanhNguyxn ThanhNguyxn force-pushed the fix/cmdpal-window-walker-stay-open branch from 661c0e4 to 5ab8506 Compare December 5, 2025 10:56
The 'Stay open after closing windows and killing processes' setting was
only working for 'End Task' command but not for 'Close Window' command.

This change updates CloseWindowCommand.Invoke() to check the
OpenAfterKillAndClose setting and return CommandResult.KeepOpen() or
CommandResult.Dismiss() accordingly, matching the behavior of
EndTaskCommand.

Fixes microsoft#43256
Implements WeakReferenceMessenger pattern as suggested by @zadjii-msft:
- Add CommunityToolkit.Mvvm dependency to WindowWalker extension
- Create RefreshWindowsMessage for communication between commands and list page
- CloseWindowCommand now sends RefreshWindowsMessage when KeepOpen
- EndTaskCommand now sends RefreshWindowsMessage when KeepOpen
- WindowWalkerListPage subscribes to message and refreshes window list
- Small delay (100ms) added to allow Windows time to close window
@ThanhNguyxn ThanhNguyxn force-pushed the fix/cmdpal-window-walker-stay-open branch from 5ab8506 to 18eec1e Compare December 5, 2025 11:23
public void Receive(RefreshWindowsMessage message)
{
// Small delay to allow Windows to actually close the window
System.Threading.Tasks.Task.Delay(100).ContinueWith(_ =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor nit] it would probably make more sense to delay sending of the message (since the caller actions are what requires the delay). But let's keep this.

@jiripolasek
Copy link
Collaborator

Hi @ThanhNguyxn, it’s best to avoid force-pushing changes to a branch under review—especially without a reason. Doing so resets the checks and forces maintainers to review it again, pushing it to the back of the queue.

Before marking a PR as ready for review or submitting further changes, please make sure all unit tests pass and that you’ve manually tested the changes and their impact on the application.

@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jiripolasek
Copy link
Collaborator

18eec1e LGTM

@michaeljolley
Copy link
Contributor

@ThanhNguyxn, thanks for attempting to contribute, but after multiple attempts, we can't get your code to compile. In this instance, you also force pushed an unrelated change. That's considered very bad form. Good luck in the future. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command Palette: Window Walker: stay open after closing windows option does not work

4 participants