mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[CmdPal] Single settings window (#38069)
## Summary of the Pull Request Make settings window single. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** https://github.com/zadjii-msft/PowerToys/issues/581 ## Validation Steps Performed Manual test. - Open settings windows multiple times - Activate minimized settings window
This commit is contained in:
committed by
GitHub
parent
4d7691a56f
commit
7368458a72
@@ -0,0 +1,9 @@
|
|||||||
|
// 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.UI.ViewModels.Messages;
|
||||||
|
|
||||||
|
public record SettingsWindowClosedMessage
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
|||||||
IRecipient<ClearSearchMessage>,
|
IRecipient<ClearSearchMessage>,
|
||||||
IRecipient<HandleCommandResultMessage>,
|
IRecipient<HandleCommandResultMessage>,
|
||||||
IRecipient<LaunchUriMessage>,
|
IRecipient<LaunchUriMessage>,
|
||||||
|
IRecipient<SettingsWindowClosedMessage>,
|
||||||
INotifyPropertyChanged
|
INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private readonly DispatcherQueue _queue = DispatcherQueue.GetForCurrentThread();
|
private readonly DispatcherQueue _queue = DispatcherQueue.GetForCurrentThread();
|
||||||
@@ -50,6 +51,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
|||||||
|
|
||||||
private readonly Lock _invokeLock = new();
|
private readonly Lock _invokeLock = new();
|
||||||
private Task? _handleInvokeTask;
|
private Task? _handleInvokeTask;
|
||||||
|
private SettingsWindow? _settingsWindow;
|
||||||
|
|
||||||
public ShellViewModel ViewModel { get; private set; } = App.Current.Services.GetService<ShellViewModel>()!;
|
public ShellViewModel ViewModel { get; private set; } = App.Current.Services.GetService<ShellViewModel>()!;
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
|||||||
WeakReferenceMessenger.Default.Register<HandleCommandResultMessage>(this);
|
WeakReferenceMessenger.Default.Register<HandleCommandResultMessage>(this);
|
||||||
WeakReferenceMessenger.Default.Register<OpenSettingsMessage>(this);
|
WeakReferenceMessenger.Default.Register<OpenSettingsMessage>(this);
|
||||||
WeakReferenceMessenger.Default.Register<HotkeySummonMessage>(this);
|
WeakReferenceMessenger.Default.Register<HotkeySummonMessage>(this);
|
||||||
|
WeakReferenceMessenger.Default.Register<SettingsWindowClosedMessage>(this);
|
||||||
|
|
||||||
WeakReferenceMessenger.Default.Register<ShowDetailsMessage>(this);
|
WeakReferenceMessenger.Default.Register<ShowDetailsMessage>(this);
|
||||||
WeakReferenceMessenger.Default.Register<HideDetailsMessage>(this);
|
WeakReferenceMessenger.Default.Register<HideDetailsMessage>(this);
|
||||||
@@ -396,8 +399,12 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
|||||||
// Also hide our details pane about here, if we had one
|
// Also hide our details pane about here, if we had one
|
||||||
HideDetails();
|
HideDetails();
|
||||||
|
|
||||||
var settingsWindow = new SettingsWindow();
|
if (_settingsWindow == null)
|
||||||
settingsWindow.Activate();
|
{
|
||||||
|
_settingsWindow = new SettingsWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
_settingsWindow.Activate();
|
||||||
|
|
||||||
WeakReferenceMessenger.Default.Send<UpdateCommandBarMessage>(new(null));
|
WeakReferenceMessenger.Default.Send<UpdateCommandBarMessage>(new(null));
|
||||||
});
|
});
|
||||||
@@ -458,6 +465,8 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
|||||||
_ = DispatcherQueue.TryEnqueue(() => SummonOnUiThread(message));
|
_ = DispatcherQueue.TryEnqueue(() => SummonOnUiThread(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Receive(SettingsWindowClosedMessage message) => _settingsWindow = null;
|
||||||
|
|
||||||
private void SummonOnUiThread(HotkeySummonMessage message)
|
private void SummonOnUiThread(HotkeySummonMessage message)
|
||||||
{
|
{
|
||||||
var settings = App.Current.Services.GetService<SettingsModel>()!;
|
var settings = App.Current.Services.GetService<SettingsModel>()!;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
Title="SettingsWindow"
|
Title="SettingsWindow"
|
||||||
Activated="Window_Activated"
|
Activated="Window_Activated"
|
||||||
|
Closed="Window_Closed"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Window.SystemBackdrop>
|
<Window.SystemBackdrop>
|
||||||
<MicaBackdrop />
|
<MicaBackdrop />
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ public sealed partial class SettingsWindow : Window,
|
|||||||
WeakReferenceMessenger.Default.Send<WindowActivatedEventArgs>(args);
|
WeakReferenceMessenger.Default.Send<WindowActivatedEventArgs>(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Window_Closed(object sender, WindowEventArgs args)
|
||||||
|
{
|
||||||
|
WeakReferenceMessenger.Default.Send<SettingsWindowClosedMessage>();
|
||||||
|
}
|
||||||
|
|
||||||
public void Receive(QuitMessage message)
|
public void Receive(QuitMessage message)
|
||||||
{
|
{
|
||||||
// This might come in on a background thread
|
// This might come in on a background thread
|
||||||
|
|||||||
Reference in New Issue
Block a user