diff --git a/src/modules/cmdpal/Tests/Microsoft.CmdPal.Ext.WindowWalker.UnitTests/Settings.cs b/src/modules/cmdpal/Tests/Microsoft.CmdPal.Ext.WindowWalker.UnitTests/Settings.cs
index cbbe365a1b..9fba1bf1ed 100644
--- a/src/modules/cmdpal/Tests/Microsoft.CmdPal.Ext.WindowWalker.UnitTests/Settings.cs
+++ b/src/modules/cmdpal/Tests/Microsoft.CmdPal.Ext.WindowWalker.UnitTests/Settings.cs
@@ -53,7 +53,7 @@ public class Settings : ISettingsInterface
public bool KillProcessTree => killProcessTree;
- public bool OpenAfterKillAndClose => openAfterKillAndClose;
+ public bool KeepOpenAfterKillAndClose => openAfterKillAndClose;
public bool HideKillProcessOnElevatedProcesses => hideKillProcessOnElevatedProcesses;
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs
index 73f1c99811..8a9570f14a 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/CloseWindowCommand.cs
@@ -2,7 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+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;
namespace Microsoft.CmdPal.Ext.WindowWalker.Commands;
@@ -26,6 +30,7 @@ internal sealed partial class CloseWindowCommand : InvokableCommand
}
_window.CloseThisWindow();
- return CommandResult.Dismiss();
+ WeakReferenceMessenger.Default.Send(new RefreshWindowsMessage());
+ return SettingsManager.Instance.KeepOpenAfterKillAndClose ? CommandResult.KeepOpen() : CommandResult.Dismiss();
}
}
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs
index aa8648a459..cd52053d37 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Commands/EndTaskCommand.cs
@@ -2,7 +2,12 @@
// 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 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;
namespace Microsoft.CmdPal.Ext.WindowWalker.Commands;
@@ -57,16 +62,13 @@ internal sealed partial class EndTaskCommand : InvokableCommand
// Kill process
window.Process.KillThisProcess(SettingsManager.Instance.KillProcessTree);
- return !SettingsManager.Instance.OpenAfterKillAndClose;
+ return !SettingsManager.Instance.KeepOpenAfterKillAndClose;
}
public override ICommandResult Invoke()
{
- if (KillProcess(_window))
- {
- return CommandResult.Dismiss();
- }
-
- return CommandResult.KeepOpen();
+ WeakReferenceMessenger.Default.Send(new RefreshWindowsMessage());
+ var shouldHide = KillProcess(_window);
+ return shouldHide ? CommandResult.Dismiss() : CommandResult.KeepOpen();
}
}
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ISettingsInterface.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ISettingsInterface.cs
index de3827c76a..1bd2d0b184 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ISettingsInterface.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/ISettingsInterface.cs
@@ -16,7 +16,7 @@ public interface ISettingsInterface
public bool KillProcessTree { get; }
- public bool OpenAfterKillAndClose { get; }
+ public bool KeepOpenAfterKillAndClose { get; }
public bool HideKillProcessOnElevatedProcesses { get; }
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs
index 54ebb72437..068219fbcd 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Helpers/SettingsManager.cs
@@ -45,7 +45,7 @@ public class SettingsManager : JsonSettingsManager, ISettingsInterface
false);
private readonly ToggleSetting _openAfterKillAndClose = new(
- Namespaced(nameof(OpenAfterKillAndClose)),
+ Namespaced(nameof(KeepOpenAfterKillAndClose)),
Resources.windowwalker_SettingOpenAfterKillAndClose,
Resources.windowwalker_SettingOpenAfterKillAndClose_Description,
false);
@@ -84,7 +84,7 @@ public class SettingsManager : JsonSettingsManager, ISettingsInterface
public bool KillProcessTree => _killProcessTree.Value;
- public bool OpenAfterKillAndClose => _openAfterKillAndClose.Value;
+ public bool KeepOpenAfterKillAndClose => _openAfterKillAndClose.Value;
public bool HideKillProcessOnElevatedProcesses => _hideKillProcessOnElevatedProcesses.Value;
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Messages/RefreshWindowsMessage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Messages/RefreshWindowsMessage.cs
new file mode 100644
index 0000000000..6d9916a502
--- /dev/null
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Messages/RefreshWindowsMessage.cs
@@ -0,0 +1,7 @@
+// 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;
+
+public record RefreshWindowsMessage(bool Delay = true);
diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Microsoft.CmdPal.Ext.WindowWalker.csproj b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Microsoft.CmdPal.Ext.WindowWalker.csproj
index 641a8677ab..2fb1f784a5 100644
--- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Microsoft.CmdPal.Ext.WindowWalker.csproj
+++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Microsoft.CmdPal.Ext.WindowWalker.csproj
@@ -18,6 +18,9 @@
+
+
+
Resources.resx
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 f6f466ba47..ff46dc987e 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
@@ -2,12 +2,18 @@
// 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.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;
namespace Microsoft.CmdPal.Ext.WindowWalker.Pages;
-internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposable
+internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposable, IRecipient
{
private System.Threading.CancellationTokenSource _cancellationTokenSource = new();
@@ -26,6 +32,8 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl
Title = Resources.window_walker_top_level_command_title,
Subtitle = Resources.windowwalker_NoResultsMessage,
};
+
+ WeakReferenceMessenger.Default.Register(this);
}
public override void UpdateSearchText(string oldSearch, string newSearch)
@@ -75,19 +83,51 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl
public override IListItem[] GetItems() => Query(SearchText);
+ public void Receive(RefreshWindowsMessage message)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (!message.Delay)
+ {
+ Refresh();
+ }
+ else
+ {
+ Task.Run(async () =>
+ {
+ await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false);
+ Refresh();
+ });
+ }
+ }
+
+ private void Refresh()
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ RaiseItemsChanged();
+ }
+
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
- public void Dispose(bool disposing)
+ private void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
- _cancellationTokenSource.Dispose();
+ WeakReferenceMessenger.Default.UnregisterAll(this);
+ _cancellationTokenSource?.Dispose();
_disposed = true;
}
}