mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-31 14:35:18 +00:00
[settings-ui] Settings WinUI3 (#17797)
* Add Settings.WinUI3 project * New namespace * Activation and Services * Assets and Behaviors * Converters and Helpers * Controls * View and ViewModels * Styles and Themes * OOBE * Strings * Small App moves * [check] Project files - publish profiles and launchSettings.json * [using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name workaround * [WIP] Workarounds to make it work * Fix suppressed warnings - naming * Add code analysis * Fix KBMPage and App dispatcher Fix MessageBox - replace with MessageDialog * Fix ImageResizerPage & mark ColorPickerButton with TODO * Add icon to windows Cleanup MainWindow.xaml.cs and OobeWindow.xaml.cs MainWindows and OobeWindow management * App Icon No framework and runtime subdirs * Remove PowerToys.Settings and Settings.UI from solution Update output paths * Installer work & publish.cmd * Fix dispatcher crashes * Fix crashes * Add all dlls to installer Cleanup installer Add OpenOOBE and OpenScoobe logic Fix minor issues Fix update scenario - REINSTALLMODE * Rename back namespaces, project name and project dir * [wip] move to winappsdk 1.1 * Fix propagating isElevated & installer runtimes dlls * Remove obsolete dir/file * PowerToys.Interop to netstandard2.0 * Move everything to .Net6 * [Settings] Always launch settings process non-elevated (#17791) * Move back to WinAppSdk 1.0.1 * Add Settings.WinUI3 project * New namespace * Activation and Services * Assets and Behaviors * Converters and Helpers * Controls * View and ViewModels * Styles and Themes * OOBE * Strings * Small App moves * [check] Project files - publish profiles and launchSettings.json * [using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name workaround * [WIP] Workarounds to make it work * Fix suppressed warnings - naming * Add code analysis * Fix KBMPage and App dispatcher Fix MessageBox - replace with MessageDialog * Fix ImageResizerPage & mark ColorPickerButton with TODO * Add icon to windows Cleanup MainWindow.xaml.cs and OobeWindow.xaml.cs MainWindows and OobeWindow management * App Icon No framework and runtime subdirs * Remove PowerToys.Settings and Settings.UI from solution Update output paths * Installer work & publish.cmd * Fix dispatcher crashes * Fix crashes * Add all dlls to installer Cleanup installer Add OpenOOBE and OpenScoobe logic Fix minor issues Fix update scenario - REINSTALLMODE * Rename back namespaces, project name and project dir * [wip] move to winappsdk 1.1 * Fix propagating isElevated & installer runtimes dlls * Remove obsolete dir/file * PowerToys.Interop to netstandard2.0 * Move everything to .Net6 * [Settings] Always launch settings process non-elevated (#17791) * Move back to WinAppSdk 1.0.1 * Revert merge conflict ARM64 removal * Fix KBM Browse overlay image button * Bring back settings publish profile * Update release.yml * Change target frameworkd windows version * [Setup] Add Windows Application Runtime SDK (#17809) * Update requirements doc * Update compiling docs * Fix signing * Fix Settings exe and dll versions * Add exception for dlls that have version 1.0.0.0 * Fix powershell condition Co-authored-by: Andrey Nekrasov <yuyoyuppe@users.noreply.github.com>
This commit is contained in:
108
src/settings-ui/Settings.UI/MainWindow.xaml.cs
Normal file
108
src/settings-ui/Settings.UI/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using Microsoft.PowerLauncher.Telemetry;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.Data.Json;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty window that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
var bootTime = new System.Diagnostics.Stopwatch();
|
||||
bootTime.Start();
|
||||
|
||||
ShellPage.SetElevationStatus(App.IsElevated);
|
||||
ShellPage.SetIsUserAnAdmin(App.IsUserAnAdmin);
|
||||
|
||||
// Set window icon
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
||||
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
||||
appWindow.SetIcon("icon.ico");
|
||||
|
||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||
Title = loader.GetString("SettingsWindow_Title");
|
||||
|
||||
// send IPC Message
|
||||
ShellPage.SetDefaultSndMessageCallback(msg =>
|
||||
{
|
||||
// IPC Manager is null when launching runner directly
|
||||
App.GetTwoWayIPCManager()?.Send(msg);
|
||||
});
|
||||
|
||||
// send IPC Message
|
||||
ShellPage.SetRestartAdminSndMessageCallback(msg =>
|
||||
{
|
||||
App.GetTwoWayIPCManager()?.Send(msg);
|
||||
Environment.Exit(0); // close application
|
||||
});
|
||||
|
||||
// send IPC Message
|
||||
ShellPage.SetCheckForUpdatesMessageCallback(msg =>
|
||||
{
|
||||
App.GetTwoWayIPCManager()?.Send(msg);
|
||||
});
|
||||
|
||||
// open oobe
|
||||
ShellPage.SetOpenOobeCallback(() =>
|
||||
{
|
||||
if (App.GetOobeWindow() == null)
|
||||
{
|
||||
App.SetOobeWindow(new OobeWindow(Microsoft.PowerToys.Settings.UI.OOBE.Enums.PowerToysModules.Overview));
|
||||
}
|
||||
|
||||
App.GetOobeWindow().Activate();
|
||||
});
|
||||
|
||||
this.InitializeComponent();
|
||||
|
||||
// receive IPC Message
|
||||
App.IPCMessageReceivedCallback = (string msg) =>
|
||||
{
|
||||
if (ShellPage.ShellHandler.IPCResponseHandleList != null)
|
||||
{
|
||||
var success = JsonObject.TryParse(msg, out JsonObject json);
|
||||
if (success)
|
||||
{
|
||||
foreach (Action<JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList)
|
||||
{
|
||||
handle(json);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("Failed to parse JSON from IPC message.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bootTime.Stop();
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
|
||||
}
|
||||
|
||||
public void NavigateToSection(System.Type type)
|
||||
{
|
||||
ShellPage.Navigate(type);
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, WindowEventArgs args)
|
||||
{
|
||||
App.ClearSettingsWindow();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user