mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +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:
@@ -12,6 +12,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Windows.Data.Json;
|
||||
@@ -75,7 +76,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
// open main window
|
||||
ShellPage.SetOpenMainWindowCallback(type =>
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
||||
DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, () =>
|
||||
App.OpenSettingsWindow(type));
|
||||
});
|
||||
|
||||
@@ -106,30 +107,8 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
return needToUpdate;
|
||||
});
|
||||
|
||||
// open oobe
|
||||
ShellPage.SetOpenOobeCallback(() =>
|
||||
{
|
||||
if (App.GetOobeWindow() == null)
|
||||
{
|
||||
App.SetOobeWindow(new OobeWindow(OOBE.Enums.PowerToysModules.Overview));
|
||||
}
|
||||
|
||||
App.GetOobeWindow().Activate();
|
||||
});
|
||||
|
||||
// open whats new window
|
||||
ShellPage.SetOpenWhatIsNewCallback(() =>
|
||||
{
|
||||
if (App.GetScoobeWindow() == null)
|
||||
{
|
||||
App.SetScoobeWindow(new ScoobeWindow());
|
||||
}
|
||||
|
||||
App.GetScoobeWindow().Activate();
|
||||
});
|
||||
|
||||
this.InitializeComponent();
|
||||
SetAppTitleBar();
|
||||
SetTitleBar();
|
||||
|
||||
// receive IPC Message
|
||||
App.IPCMessageReceivedCallback = (string msg) =>
|
||||
@@ -156,21 +135,22 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
|
||||
}
|
||||
|
||||
private void SetAppTitleBar()
|
||||
private void SetTitleBar()
|
||||
{
|
||||
// We need to assign the window here so it can configure the custom title bar area correctly.
|
||||
shellPage.TitleBar.Window = this;
|
||||
this.ExtendsContentIntoTitleBar = true;
|
||||
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(this));
|
||||
}
|
||||
|
||||
public void NavigateToSection(System.Type type)
|
||||
public void NavigateToSection(Type type)
|
||||
{
|
||||
ShellPage.Navigate(type);
|
||||
}
|
||||
|
||||
public void CloseHiddenWindow()
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
var hWnd = WindowNative.GetWindowHandle(this);
|
||||
if (!NativeMethods.IsWindowVisible(hWnd))
|
||||
{
|
||||
Close();
|
||||
@@ -179,10 +159,10 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
private void Window_Closed(object sender, WindowEventArgs args)
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
var hWnd = WindowNative.GetWindowHandle(this);
|
||||
WindowHelper.SerializePlacement(hWnd);
|
||||
|
||||
if (App.GetOobeWindow() == null && App.GetScoobeWindow() == null)
|
||||
if (!App.IsOobeOrScoobeOpen())
|
||||
{
|
||||
App.ClearSettingsWindow();
|
||||
}
|
||||
@@ -198,10 +178,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
private void Window_Activated_SetIcon(object sender, WindowActivatedEventArgs args)
|
||||
{
|
||||
// Set window icon
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
||||
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
||||
appWindow.SetIcon("Assets\\Settings\\icon.ico");
|
||||
this.SetIcon("Assets\\Settings\\icon.ico");
|
||||
}
|
||||
|
||||
private void Window_Activated(object sender, WindowActivatedEventArgs args)
|
||||
@@ -209,7 +186,7 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
if (args.WindowActivationState != WindowActivationState.Deactivated)
|
||||
{
|
||||
this.Activated -= Window_Activated;
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
var hWnd = WindowNative.GetWindowHandle(this);
|
||||
var placement = WindowHelper.DeserializePlacementOrDefault(hWnd);
|
||||
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user