mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
<!-- 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 TO DO: Upgrade to the latest version of MarkdownTextBlock: https://github.com/CommunityToolkit/Labs-Windows/pull/771 This PR introduces the following changes: **Removed the custom titlebars on the OOBE Window, and replaced it with the inbox WinUI `TitleBar` control.** **New "What's new" experience following the VS Code release notes experience** - Created a new SCOOBE Windows that is a standalone window to better visualize release notes. - Adding a nav menu on the left to easily switch between release notes, instead of a long page. - Point releases are combined with the latest main release.. e.g. 0.96.1 is rendered above 0.96.0. - The 'hero image' on main release notes will automatically be rendered at the top of the page. - Improved markdown styling for better readability. - Pull requests links can now be clicked. - Upgraded `CommunityToolkit.Labs.MarkdownTextblock` to the latest version as it includes much needed bugfixes. <img width="1234" height="819" alt="image" src="https://github.com/user-attachments/assets/447b3136-306b-4f24-bc7a-c022a99e8e51" /> Note: the blurry image shown above will be replaced in new releases by an image that fits the right dimensions. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] 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: Leilei Zhang <leilzh@microsoft.com>
229 lines
8.0 KiB
C#
229 lines
8.0 KiB
C#
// 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 System.Threading.Tasks;
|
|
using ManagedCommon;
|
|
using Microsoft.PowerLauncher.Telemetry;
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
using Microsoft.PowerToys.Settings.UI.Views;
|
|
using Microsoft.PowerToys.Telemetry;
|
|
using Microsoft.UI;
|
|
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
using Windows.Data.Json;
|
|
using WinRT.Interop;
|
|
using WinUIEx;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI
|
|
{
|
|
public sealed partial class MainWindow : WindowEx
|
|
{
|
|
public MainWindow(bool createHidden = false)
|
|
{
|
|
var bootTime = new System.Diagnostics.Stopwatch();
|
|
bootTime.Start();
|
|
|
|
this.Activated += Window_Activated_SetIcon;
|
|
|
|
App.ThemeService.ThemeChanged += OnThemeChanged;
|
|
App.ThemeService.ApplyTheme();
|
|
|
|
this.ExtendsContentIntoTitleBar = true;
|
|
|
|
ShellPage.SetElevationStatus(App.IsElevated);
|
|
ShellPage.SetIsUserAnAdmin(App.IsUserAnAdmin);
|
|
|
|
var hWnd = WindowNative.GetWindowHandle(this);
|
|
var placement = WindowHelper.DeserializePlacementOrDefault(hWnd);
|
|
if (createHidden)
|
|
{
|
|
placement.ShowCmd = NativeMethods.SW_HIDE;
|
|
|
|
// Restore the last known placement on the first activation
|
|
this.Activated += Window_Activated;
|
|
}
|
|
|
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
|
|
|
var loader = ResourceLoaderInstance.ResourceLoader;
|
|
Title = App.IsElevated ? loader.GetString("SettingsWindow_AdminTitle") : 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 main window
|
|
ShellPage.SetOpenMainWindowCallback(type =>
|
|
{
|
|
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
|
App.OpenSettingsWindow(type));
|
|
});
|
|
|
|
// open main window
|
|
ShellPage.SetUpdatingGeneralSettingsCallback((ModuleType moduleType, bool isEnabled) =>
|
|
{
|
|
SettingsRepository<GeneralSettings> repository = SettingsRepository<GeneralSettings>.GetInstance(SettingsUtils.Default);
|
|
GeneralSettings generalSettingsConfig = repository.SettingsConfig;
|
|
bool needToUpdate = ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, moduleType) != isEnabled;
|
|
|
|
if (needToUpdate)
|
|
{
|
|
ModuleHelper.SetIsModuleEnabled(generalSettingsConfig, moduleType, isEnabled);
|
|
var outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
|
|
|
|
// Save settings to file
|
|
SettingsUtils.Default.SaveSettings(generalSettingsConfig.ToJsonString());
|
|
|
|
// Send IPC message asynchronously to avoid blocking UI and potential recursive calls
|
|
Task.Run(() =>
|
|
{
|
|
ShellPage.SendDefaultIPCMessage(outgoing.ToString());
|
|
});
|
|
|
|
ShellPage.ShellHandler?.SignalGeneralDataUpdate();
|
|
}
|
|
|
|
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();
|
|
|
|
// 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 });
|
|
}
|
|
|
|
private void SetAppTitleBar()
|
|
{
|
|
// We need to assign the window here so it can configure the custom title bar area correctly.
|
|
shellPage.TitleBar.Window = this;
|
|
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(WindowNative.GetWindowHandle(this));
|
|
}
|
|
|
|
public void NavigateToSection(System.Type 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)
|
|
{
|
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
|
WindowHelper.SerializePlacement(hWnd);
|
|
|
|
if (App.GetOobeWindow() == null && App.GetScoobeWindow() == null)
|
|
{
|
|
App.ClearSettingsWindow();
|
|
}
|
|
else
|
|
{
|
|
args.Handled = true;
|
|
NativeMethods.ShowWindow(hWnd, NativeMethods.SW_HIDE);
|
|
}
|
|
|
|
App.ThemeService.ThemeChanged -= OnThemeChanged;
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
private void Window_Activated(object sender, WindowActivatedEventArgs args)
|
|
{
|
|
if (args.WindowActivationState != WindowActivationState.Deactivated)
|
|
{
|
|
this.Activated -= Window_Activated;
|
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
|
var placement = WindowHelper.DeserializePlacementOrDefault(hWnd);
|
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
|
}
|
|
}
|
|
|
|
private void OnThemeChanged(object sender, ElementTheme theme)
|
|
{
|
|
WindowHelper.SetTheme(this, theme);
|
|
}
|
|
|
|
internal void EnsurePageIsSelected()
|
|
{
|
|
ShellPage.EnsurePageIsSelected();
|
|
}
|
|
}
|
|
}
|