Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// 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 System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.Ext.WindowWalker.Components;
using Microsoft.CmdPal.Ext.WindowWalker.Helpers;
using Microsoft.CmdPal.Ext.WindowWalker.Messages;
using Microsoft.CmdPal.Ext.WindowWalker.Properties;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
Expand All @@ -33,6 +31,14 @@ public override ICommandResult Invoke()
}

_window.CloseThisWindow();

if (SettingsManager.Instance.OpenAfterKillAndClose)
{
// Send message to refresh window list after closing
WeakReferenceMessenger.Default.Send(new RefreshWindowsMessage());
return CommandResult.KeepOpen();
}

return CommandResult.Dismiss();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.Ext.WindowWalker.Components;
using Microsoft.CmdPal.Ext.WindowWalker.Helpers;
using Microsoft.CmdPal.Ext.WindowWalker.Messages;
using Microsoft.CmdPal.Ext.WindowWalker.Properties;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
Expand Down Expand Up @@ -70,11 +68,15 @@ private static bool KillProcess(Window window)

public override ICommandResult Invoke()
{
if (KillProcess(_window))
var shouldDismiss = KillProcess(_window);

if (shouldDismiss)
{
return CommandResult.Dismiss();
}

// Send message to refresh window list after killing process
WeakReferenceMessenger.Default.Send(new RefreshWindowsMessage());
return CommandResult.KeepOpen();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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.

namespace Microsoft.CmdPal.Ext.WindowWalker.Messages;

/// <summary>
/// Message sent when the window list needs to be refreshed.
/// Used by CloseWindowCommand and EndTaskCommand to notify
/// WindowWalkerListPage to refresh after closing/killing a window.
/// </summary>
internal sealed class RefreshWindowsMessage
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<ItemGroup>
<None Remove="Assets\WindowWalker.svg" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\..\common\ManagedCsWin32\ManagedCsWin32.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.Ext.WindowWalker.Components;
using Microsoft.CmdPal.Ext.WindowWalker.Messages;
using Microsoft.CmdPal.Ext.WindowWalker.Properties;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;

namespace Microsoft.CmdPal.Ext.WindowWalker.Pages;

internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposable
internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposable, IRecipient<RefreshWindowsMessage>
{
private System.Threading.CancellationTokenSource _cancellationTokenSource = new();

Expand All @@ -31,6 +33,22 @@ public WindowWalkerListPage()
Title = Resources.window_walker_top_level_command_title,
Subtitle = Resources.windowwalker_NoResultsMessage,
};

// Register to receive refresh messages
WeakReferenceMessenger.Default.Register(this);
}

/// <summary>
/// Handle the RefreshWindowsMessage to refresh the window list
/// after a window is closed or a process is killed.
/// </summary>
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.

{
RaiseItemsChanged(0);
});
}

public override void UpdateSearchText(string oldSearch, string newSearch) =>
Expand Down Expand Up @@ -66,6 +84,7 @@ public void Dispose(bool disposing)
{
if (disposing)
{
WeakReferenceMessenger.Default.Unregister<RefreshWindowsMessage>(this);
_cancellationTokenSource?.Dispose();
_disposed = true;
}
Expand Down