Files
PowerToys/src/modules/powerdisplay/PowerDisplay/Program.cs
Yu Leng 0bbfc8015a Add GPO rule and profile management for PowerDisplay
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.
2025-12-01 04:32:29 +08:00

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;
}
}
}
}