mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Hide main settings window instead of closing (#17960)
* Hide main settings window instead of closing * Proper closing * Create Settings window hidden if opening OOBE/SCOOBE
This commit is contained in:
@@ -149,9 +149,11 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Create the Settings window so that it's fully initialized and
|
// Create the Settings window hidden so that it's fully initialized and
|
||||||
// it will be ready to receive the notification if the user opens
|
// it will be ready to receive the notification if the user opens
|
||||||
// the Settings from the tray icon.
|
// the Settings from the tray icon.
|
||||||
|
settingsWindow = new MainWindow(true);
|
||||||
|
|
||||||
if (ShowOobe)
|
if (ShowOobe)
|
||||||
{
|
{
|
||||||
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
|
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
internal const int SPI_GETDESKWALLPAPER = 0x0073;
|
internal const int SPI_GETDESKWALLPAPER = 0x0073;
|
||||||
internal const int SW_SHOWNORMAL = 1;
|
internal const int SW_SHOWNORMAL = 1;
|
||||||
internal const int SW_SHOWMAXIMIZED = 3;
|
internal const int SW_SHOWMAXIMIZED = 3;
|
||||||
|
internal const int SW_HIDE = 0;
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
internal static extern IntPtr GetActiveWindow();
|
internal static extern IntPtr GetActiveWindow();
|
||||||
@@ -44,6 +45,9 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern int GetDpiForWindow(System.IntPtr hWnd);
|
public static extern int GetDpiForWindow(System.IntPtr hWnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool AllowSetForegroundWindow(int dwProcessId);
|
public static extern bool AllowSetForegroundWindow(int dwProcessId);
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class MainWindow : Window
|
public sealed partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow(bool createHidden = false)
|
||||||
{
|
{
|
||||||
var bootTime = new System.Diagnostics.Stopwatch();
|
var bootTime = new System.Diagnostics.Stopwatch();
|
||||||
bootTime.Start();
|
bootTime.Start();
|
||||||
@@ -37,6 +37,11 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
appWindow.SetIcon("icon.ico");
|
appWindow.SetIcon("icon.ico");
|
||||||
|
|
||||||
var placement = Utils.DeserializePlacementOrDefault(hWnd);
|
var placement = Utils.DeserializePlacementOrDefault(hWnd);
|
||||||
|
if (createHidden)
|
||||||
|
{
|
||||||
|
placement.ShowCmd = NativeMethods.SW_HIDE;
|
||||||
|
}
|
||||||
|
|
||||||
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
||||||
|
|
||||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||||
@@ -105,12 +110,29 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
ShellPage.Navigate(type);
|
ShellPage.Navigate(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CloseHiddenWindow()
|
||||||
|
{
|
||||||
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||||
|
if (!NativeMethods.IsWindowVisible(hWnd))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Window_Closed(object sender, WindowEventArgs args)
|
private void Window_Closed(object sender, WindowEventArgs args)
|
||||||
{
|
{
|
||||||
App.ClearSettingsWindow();
|
|
||||||
|
|
||||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||||
Utils.SerializePlacement(hWnd);
|
Utils.SerializePlacement(hWnd);
|
||||||
|
|
||||||
|
if (App.GetOobeWindow() == null)
|
||||||
|
{
|
||||||
|
App.ClearSettingsWindow();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
NativeMethods.ShowWindow(hWnd, NativeMethods.SW_HIDE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,12 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
private void Window_Closed(object sender, WindowEventArgs args)
|
private void Window_Closed(object sender, WindowEventArgs args)
|
||||||
{
|
{
|
||||||
App.ClearOobeWindow();
|
App.ClearOobeWindow();
|
||||||
|
|
||||||
|
var mainWindow = App.GetSettingsWindow();
|
||||||
|
if (mainWindow != null)
|
||||||
|
{
|
||||||
|
mainWindow.CloseHiddenWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user