mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Introduced a new GPO rule to manage PowerDisplay's enabled state via Group Policy, including updates to `GPOWrapper` and policy files (`PowerToys.admx` and `PowerToys.adml`). Enhanced the PowerDisplay UI with profile management features, including quick apply, add, edit, and delete functionality. Updated `MainWindow.xaml` and `PowerDisplayPage.xaml` to support these changes, and added localized strings for improved accessibility. Refactored `MainViewModel` to include a `Profiles` collection, `HasProfiles` property, and `ApplyProfileCommand`. Added methods to load profiles from disk and signal updates to PowerDisplay. Improved error handling in `DdcCiController` and `WmiController` with input validation and WMI error classification. Optimized handle cleanup in `PhysicalMonitorHandleManager` with a more efficient algorithm. Refactored `dllmain.cpp` to prevent duplicate PowerDisplay process launches. Updated initialization logic in `MainWindow.xaml.cs` to ensure proper ViewModel setup. Localized strings for tooltips, warnings, and dialogs. Improved async behavior, logging, and UI accessibility.
61 lines
1.9 KiB
C#
61 lines
1.9 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;
|
|
using ManagedCommon;
|
|
using Microsoft.UI.Dispatching;
|
|
using Microsoft.Windows.AppLifecycle;
|
|
|
|
namespace PowerDisplay
|
|
{
|
|
public static class Program
|
|
{
|
|
[STAThread]
|
|
public static void Main(string[] args)
|
|
{
|
|
Logger.InitializeLogger("\\PowerDisplay\\Logs");
|
|
|
|
WinRT.ComWrappersSupport.InitializeComWrappers();
|
|
|
|
// Parse command line arguments: args[0] = runner_pid (Awake pattern)
|
|
int runnerPid = -1;
|
|
|
|
if (args.Length >= 1)
|
|
{
|
|
if (int.TryParse(args[0], out int parsedPid))
|
|
{
|
|
runnerPid = parsedPid;
|
|
Logger.LogInfo($"PowerDisplay started with runner_pid={runnerPid}");
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning($"Failed to parse PID from args[0]: {args[0]}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning("PowerDisplay started without runner PID. Running in standalone mode.");
|
|
}
|
|
|
|
var instanceKey = AppInstance.FindOrRegisterForKey("PowerToys_PowerDisplay_Instance");
|
|
|
|
if (instanceKey.IsCurrent)
|
|
{
|
|
Microsoft.UI.Xaml.Application.Start((p) =>
|
|
{
|
|
var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
|
|
SynchronizationContext.SetSynchronizationContext(context);
|
|
_ = new App(runnerPid);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Logger.LogWarning("Another instance of PowerDisplay is running. Exiting.");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|