mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
* Flatten everything and succeed build * Figure out Settings assets * Remove UseCommonOutputDirectory tag * Proper settings app path * [VCM] Fix assets location * Fix some runtime paths * [RegistryPreview]Use MRTCore specific pri file * [Hosts]Use MRTCore specific pri file * [Settings]Use MRTCore specific pri file * [Peek]Use MRTCore specific pri file * [FileLocksmith]Use MRTCore specific pri file * [ScreenRuler]Use MRTCore specific pri file * [PowerRename]Use MRTCore specific pri file * [Peek]Move assets to own folder * [FileLocksmith] Use own Assets path * [Hosts]Use own assets folder * [PowerRename]Use own assets dir * [MeasureTool] Use its own assets folder * [ImageResizer]Use its own assets path * Fix spellcheck * Fix tab instead of space in project files * Normalize target frameworks and platforms * Remove WINRT_NO_MAKE_DETECTION flag. No longer needed? * Fix AOT and Hosts locations * Fix Dll version differences on dependency * Add Common.UI.csproj as refernce to fix dll versions * Update ControlzEx to normalize dll versions * Update System.Management version to 7.0.2 * Add GPOWrapper to Registry Preview to fix dll versions * [PTRun]Reference Microsoft.Extensions.Hosting to fix dll versions * Fix remaining output paths / dll version conflicts * [KeyboardManager]Executables still on their own directories * Fix Monaco paths * WinAppSDK apps get to play outside again * Enable VCM settings again * Fix KBM Editor path again * [Monaco]Set to own Assets dir * Fix installer preamble; Fix publish. remove unneeded publishes * Remove Hardlink functions * Installer builds again (still needs work to work) * Readd Monaco to spellcheck excludes * Fix spellcheck and call publish.cmd again * [Installer] Remove components that don't need own dirs * [Installer] Refactor Power Launcher * [Installer] Refactor Color Picker * [Installer] Refactor Monaco assets * [Installer]Generate File script no longer needs to remove files * [Installer]Refactor FileLocksmith * [Installer] Refactor Hosts * [Installer]Refactor Image Resizer * [Installer]Refactor MouseUtils * [Installer]Refactor MWB * [Installer]Refactor MeasureTool * [Installer]Refactor Peek * [Installer]Refactor PowerRename and registry fixes * [Installer]Refactor RegistryPreview * [Installer]Refactor ShortcutGuide * [Installer]Refactor Settings * [Installer]Clean up some unused stuff * [Installer]Clean up stuff for user install * [Installer]Fix WinUi3Apps wxs * [Installer]Fix misplaced folders * [Installer]Move x86 VCM dll to right path * Fix monaco language list location * [Installer]Fix VCM directory reference * [CI]Fix signing * [Installer] Fix resources folder for release CI * [ci]Looks like we still ship NLog on PowerToys Run * [Settings]Add dependency to avoid dll collision with Experimentation * [RegistryPreview]Move XAML files to own path * [RegistryPreview]Fix app icon * [Hosts]Move XAML files to their own path * [FileLocksmith]Move XAML files to their own path * [Peek]Move XAML files to own path * [ScreenRuler]Move XAML files to its own path * [Settings]Move XAML to its own path * [ColorPicker]Move Resources to Assets * [ShortcutGuide]Move svgs to own Assets path * [Awake]Move images to assets path * [Runner]Remove debug checks for PowerToys Run assets * [PTRun]Move images to its own assets path * [ImageResizer]Icon for context menu on own assets path * [PowerRename]Move ico to its own path * Remove unneeded intermediary directories * Remove further int dirs * Move tests to its own output path * Fix spellcheck * spellcheck: remove warnings * [CppAnalyzers]Ignore rule in a tool * [CI]Check if all deps.json files reference same versions * fix spellcheck * [ci]Fix task identation * [ci]Add script to guard against asset conflicts * [ci]Add more deps.json audit steps in the release build * Add xbf to spellcheck expects * Fix typo in asset conflict check scripts * Fix some more dependency conflicts * Downgrade CsWinRT to have the same dll version as sdk * [ci]Do a recursive check for every deps.json * Fix spellcheck error inside comment * [ci]Fix asset script error * [ci]Name deps.json verify tasks a bit better * [ci]Improve deps json verify script output * [ci]Update WinRT version to the same running in CI * Also upgrade CsWinRT in NOTICE.MD * [PowerRename]Move XAML files to own path * [Common]Fix Settings executable path * [ci]Verify there's no xbf files in app directories * [installer]Fix firewall path * [Monaco]Move new files to their proper assets path * [Monaco]Fix paths for new files after merge * [Feedback]Removed unneeded build conditions * [Feedback]Clear vcxproj direct reference to frameworks * [Feedback]RunPlugins name to hold PTRun plugins * [Feedback]Remove unneeded foreach * [Feedback]Shortcut Guide svgs with ** in project file * [Feedback]Fix spellcheck
290 lines
13 KiB
C#
290 lines
13 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 ManagedCommon;
|
|
using Microsoft.PowerLauncher.Telemetry;
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
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 WinUIEx;
|
|
|
|
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 : WindowEx
|
|
{
|
|
public MainWindow(bool isDark, bool createHidden = false)
|
|
{
|
|
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("Assets\\Settings\\icon.ico");
|
|
|
|
// Passed by parameter, as it needs to be evaluated ASAP, otherwise there is a white flash
|
|
if (isDark)
|
|
{
|
|
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
|
}
|
|
|
|
var placement = Utils.DeserializePlacementOrDefault(hWnd);
|
|
if (createHidden)
|
|
{
|
|
placement.ShowCmd = NativeMethods.SW_HIDE;
|
|
}
|
|
|
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
|
|
|
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
|
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 main window
|
|
ShellPage.SetOpenMainWindowCallback(type =>
|
|
{
|
|
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
|
App.OpenSettingsWindow(type));
|
|
});
|
|
|
|
// open main window
|
|
ShellPage.SetUpdatingGeneralSettingsCallback((string module, bool isEnabled) =>
|
|
{
|
|
SettingsRepository<GeneralSettings> repository = SettingsRepository<GeneralSettings>.GetInstance(new SettingsUtils());
|
|
GeneralSettings generalSettingsConfig = repository.SettingsConfig;
|
|
bool needToUpdate = false;
|
|
switch (module)
|
|
{
|
|
case "AlwaysOnTop":
|
|
needToUpdate = generalSettingsConfig.Enabled.AlwaysOnTop != isEnabled;
|
|
generalSettingsConfig.Enabled.AlwaysOnTop = isEnabled; break;
|
|
case "Awake":
|
|
needToUpdate = generalSettingsConfig.Enabled.Awake != isEnabled;
|
|
generalSettingsConfig.Enabled.Awake = isEnabled; break;
|
|
case "ColorPicker":
|
|
needToUpdate = generalSettingsConfig.Enabled.ColorPicker != isEnabled;
|
|
generalSettingsConfig.Enabled.ColorPicker = isEnabled; break;
|
|
case "FancyZones":
|
|
needToUpdate = generalSettingsConfig.Enabled.FancyZones != isEnabled;
|
|
generalSettingsConfig.Enabled.FancyZones = isEnabled; break;
|
|
case "FileLocksmith":
|
|
needToUpdate = generalSettingsConfig.Enabled.FileLocksmith != isEnabled;
|
|
generalSettingsConfig.Enabled.FileLocksmith = isEnabled; break;
|
|
case "FindMyMouse":
|
|
needToUpdate = generalSettingsConfig.Enabled.FindMyMouse != isEnabled;
|
|
generalSettingsConfig.Enabled.FindMyMouse = isEnabled; break;
|
|
case "Hosts":
|
|
needToUpdate = generalSettingsConfig.Enabled.Hosts != isEnabled;
|
|
generalSettingsConfig.Enabled.Hosts = isEnabled; break;
|
|
case "ImageResizer":
|
|
needToUpdate = generalSettingsConfig.Enabled.ImageResizer != isEnabled;
|
|
generalSettingsConfig.Enabled.ImageResizer = isEnabled; break;
|
|
case "KeyboardManager":
|
|
needToUpdate = generalSettingsConfig.Enabled.KeyboardManager != isEnabled;
|
|
generalSettingsConfig.Enabled.KeyboardManager = isEnabled; break;
|
|
case "MouseHighlighter":
|
|
needToUpdate = generalSettingsConfig.Enabled.MouseHighlighter != isEnabled;
|
|
generalSettingsConfig.Enabled.MouseHighlighter = isEnabled; break;
|
|
case "MouseJump":
|
|
needToUpdate = generalSettingsConfig.Enabled.MouseJump != isEnabled;
|
|
generalSettingsConfig.Enabled.MouseJump = isEnabled; break;
|
|
case "MousePointerCrosshairs":
|
|
needToUpdate = generalSettingsConfig.Enabled.MousePointerCrosshairs != isEnabled;
|
|
generalSettingsConfig.Enabled.MousePointerCrosshairs = isEnabled; break;
|
|
case "MouseWithoutBorders":
|
|
needToUpdate = generalSettingsConfig.Enabled.MouseWithoutBorders != isEnabled;
|
|
generalSettingsConfig.Enabled.MouseWithoutBorders = isEnabled; break;
|
|
case "PastePlain":
|
|
needToUpdate = generalSettingsConfig.Enabled.PastePlain != isEnabled;
|
|
generalSettingsConfig.Enabled.PastePlain = isEnabled; break;
|
|
case "Peek":
|
|
needToUpdate = generalSettingsConfig.Enabled.Peek != isEnabled;
|
|
generalSettingsConfig.Enabled.Peek = isEnabled; break;
|
|
case "PowerRename":
|
|
needToUpdate = generalSettingsConfig.Enabled.PowerRename != isEnabled;
|
|
generalSettingsConfig.Enabled.PowerRename = isEnabled; break;
|
|
case "PowerLauncher":
|
|
needToUpdate = generalSettingsConfig.Enabled.PowerLauncher != isEnabled;
|
|
generalSettingsConfig.Enabled.PowerLauncher = isEnabled; break;
|
|
case "PowerAccent":
|
|
needToUpdate = generalSettingsConfig.Enabled.PowerAccent != isEnabled;
|
|
generalSettingsConfig.Enabled.PowerAccent = isEnabled; break;
|
|
case "RegistryPreview":
|
|
needToUpdate = generalSettingsConfig.Enabled.RegistryPreview != isEnabled;
|
|
generalSettingsConfig.Enabled.RegistryPreview = isEnabled; break;
|
|
case "MeasureTool":
|
|
needToUpdate = generalSettingsConfig.Enabled.MeasureTool != isEnabled;
|
|
generalSettingsConfig.Enabled.MeasureTool = isEnabled; break;
|
|
case "ShortcutGuide":
|
|
needToUpdate = generalSettingsConfig.Enabled.ShortcutGuide != isEnabled;
|
|
generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
|
case "PowerOCR":
|
|
needToUpdate = generalSettingsConfig.Enabled.PowerOCR != isEnabled;
|
|
generalSettingsConfig.Enabled.PowerOCR = isEnabled; break;
|
|
case "VideoConference":
|
|
needToUpdate = generalSettingsConfig.Enabled.VideoConference != isEnabled;
|
|
generalSettingsConfig.Enabled.VideoConference = isEnabled; break;
|
|
}
|
|
|
|
if (needToUpdate)
|
|
{
|
|
var outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
|
|
this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
|
{
|
|
ShellPage.SendDefaultIPCMessage(outgoing.ToString());
|
|
ShellPage.ShellHandler?.SignalGeneralDataUpdate();
|
|
});
|
|
}
|
|
|
|
return needToUpdate;
|
|
});
|
|
|
|
// open oobe
|
|
ShellPage.SetOpenOobeCallback(() =>
|
|
{
|
|
if (App.GetOobeWindow() == null)
|
|
{
|
|
App.SetOobeWindow(new OobeWindow(Microsoft.PowerToys.Settings.UI.OOBE.Enums.PowerToysModules.Overview, App.IsDarkTheme()));
|
|
}
|
|
|
|
App.GetOobeWindow().Activate();
|
|
});
|
|
|
|
// open flyout
|
|
ShellPage.SetOpenFlyoutCallback((POINT? p) =>
|
|
{
|
|
this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
|
{
|
|
if (App.GetFlyoutWindow() == null)
|
|
{
|
|
App.SetFlyoutWindow(new FlyoutWindow(p));
|
|
}
|
|
|
|
FlyoutWindow flyout = App.GetFlyoutWindow();
|
|
flyout.FlyoutAppearPosition = p;
|
|
flyout.Activate();
|
|
|
|
// 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.
|
|
Utils.BecomeForegroundWindow(flyout.GetWindowHandle());
|
|
});
|
|
});
|
|
|
|
// disable flyout hiding
|
|
ShellPage.SetDisableFlyoutHidingCallback(() =>
|
|
{
|
|
this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
|
|
{
|
|
if (App.GetFlyoutWindow() == null)
|
|
{
|
|
App.SetFlyoutWindow(new FlyoutWindow(null));
|
|
}
|
|
|
|
App.GetFlyoutWindow().ViewModel.DisableHiding();
|
|
});
|
|
});
|
|
|
|
this.InitializeComponent();
|
|
|
|
SetTheme(isDark);
|
|
|
|
// 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);
|
|
}
|
|
|
|
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);
|
|
Utils.SerializePlacement(hWnd);
|
|
|
|
if (App.GetOobeWindow() == null)
|
|
{
|
|
App.ClearSettingsWindow();
|
|
}
|
|
else
|
|
{
|
|
args.Handled = true;
|
|
NativeMethods.ShowWindow(hWnd, NativeMethods.SW_HIDE);
|
|
}
|
|
}
|
|
|
|
internal void EnsurePageIsSelected()
|
|
{
|
|
ShellPage.EnsurePageIsSelected();
|
|
}
|
|
|
|
private void SetTheme(bool isDark)
|
|
{
|
|
shellPage.RequestedTheme = isDark ? ElementTheme.Dark : ElementTheme.Light;
|
|
}
|
|
}
|
|
}
|