mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[Settings] Optimizing and cleaning up code (#44721)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request - Removing dead experiments code - Refactoring and simplifying OOBE/SCOOBE windowing code - Removing dead assets - Optimizing CmdPal assets to lower res shaving off a few MBs - Scrolling works better on the What's new page - Should be merged after: #44638 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [X] Closes: #44958 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
This commit is contained in:
@@ -13,6 +13,8 @@ using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
|
||||
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
|
||||
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
|
||||
using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
||||
using Microsoft.PowerToys.Settings.UI.Services;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
@@ -25,11 +27,14 @@ using WinUIEx;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static OobeShellViewModel OobeShellViewModel { get; } = new();
|
||||
|
||||
private OobeWindow oobeWindow;
|
||||
|
||||
private ScoobeWindow scoobeWindow;
|
||||
|
||||
private enum Arguments
|
||||
{
|
||||
PTPipeName = 1,
|
||||
@@ -231,10 +236,6 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground
|
||||
// Need to call SetForegroundWindow to actually gain focus.
|
||||
WindowHelpers.BringToForeground(settingsWindow.GetWindowHandle());
|
||||
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/issues/8948 - A window's top border incorrectly
|
||||
// renders as black on Windows 10.
|
||||
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(settingsWindow));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -245,20 +246,11 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
if (ShowOobe)
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
|
||||
OobeWindow oobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.Overview);
|
||||
oobeWindow.Activate();
|
||||
oobeWindow.ExtendsContentIntoTitleBar = true;
|
||||
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(settingsWindow));
|
||||
SetOobeWindow(oobeWindow);
|
||||
OpenOobe();
|
||||
}
|
||||
else if (ShowScoobe)
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
|
||||
ScoobeWindow newScoobeWindow = new ScoobeWindow();
|
||||
newScoobeWindow.Activate();
|
||||
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(settingsWindow));
|
||||
SetScoobeWindow(newScoobeWindow);
|
||||
OpenScoobe();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,7 +260,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
/// will be used such as when the application is launched to open a specific file.
|
||||
/// </summary>
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
var cmdArgs = Environment.GetCommandLineArgs();
|
||||
|
||||
@@ -294,8 +286,6 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
// For debugging purposes
|
||||
// Window is also needed to show MessageDialog
|
||||
settingsWindow = new MainWindow();
|
||||
settingsWindow.ExtendsContentIntoTitleBar = true;
|
||||
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(settingsWindow));
|
||||
settingsWindow.Activate();
|
||||
settingsWindow.NavigateToSection(StartupPage);
|
||||
|
||||
@@ -303,7 +293,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
GlobalHotkeyConflictManager.Initialize(message =>
|
||||
{
|
||||
// In debug mode, just log or do nothing
|
||||
System.Diagnostics.Debug.WriteLine($"IPC Message: {message}");
|
||||
Debug.WriteLine($"IPC Message: {message}");
|
||||
return 0;
|
||||
});
|
||||
#else
|
||||
@@ -335,8 +325,6 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
public static ThemeService ThemeService => themeService;
|
||||
|
||||
private static MainWindow settingsWindow;
|
||||
private static OobeWindow oobeWindow;
|
||||
private static ScoobeWindow scoobeWindow;
|
||||
|
||||
public static void ClearSettingsWindow()
|
||||
{
|
||||
@@ -348,34 +336,52 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
return settingsWindow;
|
||||
}
|
||||
|
||||
public static OobeWindow GetOobeWindow()
|
||||
public static bool IsOobeOrScoobeOpen()
|
||||
{
|
||||
return oobeWindow;
|
||||
var app = (App)Current;
|
||||
return app.oobeWindow != null || app.scoobeWindow != null;
|
||||
}
|
||||
|
||||
public static void SetOobeWindow(OobeWindow window)
|
||||
public void OpenScoobe()
|
||||
{
|
||||
oobeWindow = window;
|
||||
PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
|
||||
|
||||
if (scoobeWindow == null)
|
||||
{
|
||||
scoobeWindow = new ScoobeWindow();
|
||||
|
||||
scoobeWindow.Closed += (_, _) =>
|
||||
{
|
||||
scoobeWindow = null;
|
||||
};
|
||||
|
||||
scoobeWindow.Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowHelpers.BringToForeground(scoobeWindow.GetWindowHandle());
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearOobeWindow()
|
||||
public void OpenOobe()
|
||||
{
|
||||
oobeWindow = null;
|
||||
}
|
||||
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
|
||||
|
||||
public static ScoobeWindow GetScoobeWindow()
|
||||
{
|
||||
return scoobeWindow;
|
||||
}
|
||||
if (oobeWindow == null)
|
||||
{
|
||||
oobeWindow = new OobeWindow();
|
||||
|
||||
public static void SetScoobeWindow(ScoobeWindow window)
|
||||
{
|
||||
scoobeWindow = window;
|
||||
}
|
||||
oobeWindow.Closed += (_, _) =>
|
||||
{
|
||||
oobeWindow = null;
|
||||
};
|
||||
|
||||
public static void ClearScoobeWindow()
|
||||
{
|
||||
scoobeWindow = null;
|
||||
oobeWindow.Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowHelpers.BringToForeground(oobeWindow.GetWindowHandle());
|
||||
}
|
||||
}
|
||||
|
||||
public static Type GetPage(string settingWindow)
|
||||
@@ -399,6 +405,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
case "MouseWithoutBorders": return typeof(MouseWithoutBordersPage);
|
||||
case "Peek": return typeof(PeekPage);
|
||||
case "PowerAccent": return typeof(PowerAccentPage);
|
||||
case "PowerDisplay": return typeof(PowerDisplayPage);
|
||||
case "PowerLauncher": return typeof(PowerLauncherPage);
|
||||
case "PowerPreview": return typeof(PowerPreviewPage);
|
||||
case "PowerRename": return typeof(PowerRenamePage);
|
||||
@@ -415,7 +422,6 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
case "Workspaces": return typeof(WorkspacesPage);
|
||||
case "CmdPal": return typeof(CmdPalPage);
|
||||
case "ZoomIt": return typeof(ZoomItPage);
|
||||
case "PowerDisplay": return typeof(PowerDisplayPage);
|
||||
default:
|
||||
// Fallback to Dashboard
|
||||
Debug.Assert(false, "Unexpected SettingsWindow argument value");
|
||||
|
||||
Reference in New Issue
Block a user