mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[PT Settings] Rename "Microsoft.PowerToys.Setting.UI.Runner" to "PowerToys.Settings" (#9637)
This commit is contained in:
97
src/settings-ui/PowerToys.Settings/Program.cs
Normal file
97
src/settings-ui/PowerToys.Settings/Program.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using interop;
|
||||
using ManagedCommon;
|
||||
using Windows.UI.Popups;
|
||||
|
||||
namespace PowerToys.Settings
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
// Quantity of arguments
|
||||
private const int ArgumentsQty = 5;
|
||||
|
||||
// Create an instance of the IPC wrapper.
|
||||
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
||||
|
||||
public static bool IsElevated { get; set; }
|
||||
|
||||
public static bool IsUserAnAdmin { get; set; }
|
||||
|
||||
public static int PowerToysPID { get; set; }
|
||||
|
||||
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
using (new Microsoft.PowerToys.Settings.UI.App())
|
||||
{
|
||||
App app = new App();
|
||||
app.InitializeComponent();
|
||||
|
||||
if (args != null && args.Length >= ArgumentsQty)
|
||||
{
|
||||
_ = int.TryParse(args[2], out int powerToysPID);
|
||||
PowerToysPID = powerToysPID;
|
||||
|
||||
if (args[4] == "true")
|
||||
{
|
||||
IsElevated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsElevated = false;
|
||||
}
|
||||
|
||||
if (args[5] == "true")
|
||||
{
|
||||
IsUserAnAdmin = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsUserAnAdmin = false;
|
||||
}
|
||||
|
||||
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
||||
{
|
||||
Environment.Exit(0);
|
||||
});
|
||||
|
||||
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], (string message) =>
|
||||
{
|
||||
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
|
||||
{
|
||||
IPCMessageReceivedCallback(message);
|
||||
}));
|
||||
}
|
||||
});
|
||||
ipcmanager.Start();
|
||||
app.Run();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(
|
||||
"The application cannot be run as a standalone process. Please start the application through the runner.",
|
||||
"Forbidden",
|
||||
MessageBoxButton.OK);
|
||||
app.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
||||
{
|
||||
return ipcmanager;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user