2020-09-04 16:56:52 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-04-08 05:19:33 +08:00
|
|
|
// 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;
|
2021-09-29 18:54:05 +08:00
|
|
|
using System.Diagnostics;
|
2020-04-08 05:19:33 +08:00
|
|
|
using System.Windows;
|
2020-04-24 08:11:02 +08:00
|
|
|
using interop;
|
2020-08-18 01:00:56 +08:00
|
|
|
using ManagedCommon;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
2021-02-12 00:29:56 +08:00
|
|
|
namespace PowerToys.Settings
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2020-10-27 02:09:18 +08:00
|
|
|
public static class Program
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2021-02-18 21:11:57 +08:00
|
|
|
private enum Arguments
|
|
|
|
{
|
|
|
|
PTPipeName = 0,
|
|
|
|
SettingsPipeName,
|
|
|
|
PTPid,
|
|
|
|
Theme, // used in the old settings
|
|
|
|
ElevatedStatus,
|
|
|
|
IsUserAdmin,
|
2021-03-03 01:56:37 +08:00
|
|
|
ShowOobeWindow,
|
2021-09-29 18:54:05 +08:00
|
|
|
SettingsWindow,
|
2021-02-18 21:11:57 +08:00
|
|
|
}
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
// Quantity of arguments
|
2021-09-29 18:54:05 +08:00
|
|
|
private const int RequiredArgumentsQty = 7;
|
|
|
|
private const int RequiredAndOptionalArgumentsQty = 8;
|
2020-05-14 17:36:27 +08:00
|
|
|
|
2020-04-08 05:19:33 +08:00
|
|
|
// Create an instance of the IPC wrapper.
|
2020-04-24 08:11:02 +08:00
|
|
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
2020-04-08 05:19:33 +08:00
|
|
|
|
2020-05-06 01:02:31 +08:00
|
|
|
public static bool IsElevated { get; set; }
|
|
|
|
|
2020-05-14 17:36:27 +08:00
|
|
|
public static bool IsUserAnAdmin { get; set; }
|
|
|
|
|
2020-06-11 01:58:34 +08:00
|
|
|
public static int PowerToysPID { get; set; }
|
|
|
|
|
2020-09-04 16:56:52 +08:00
|
|
|
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
|
|
|
|
2020-04-11 06:22:07 +08:00
|
|
|
[STAThread]
|
2020-04-08 05:19:33 +08:00
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2021-02-12 00:29:56 +08:00
|
|
|
using (new Microsoft.PowerToys.Settings.UI.App())
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
|
|
|
App app = new App();
|
|
|
|
app.InitializeComponent();
|
|
|
|
|
2021-03-03 01:56:37 +08:00
|
|
|
if (args != null && args.Length >= RequiredArgumentsQty)
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
2021-02-18 21:11:57 +08:00
|
|
|
_ = int.TryParse(args[(int)Arguments.PTPid], out int powerToysPID);
|
2020-06-11 01:58:34 +08:00
|
|
|
PowerToysPID = powerToysPID;
|
|
|
|
|
2021-02-18 21:11:57 +08:00
|
|
|
IsElevated = args[(int)Arguments.ElevatedStatus] == "true";
|
|
|
|
IsUserAnAdmin = args[(int)Arguments.IsUserAdmin] == "true";
|
2021-09-29 18:54:05 +08:00
|
|
|
app.ShowOobe = args[(int)Arguments.ShowOobeWindow] == "true";
|
2020-05-14 17:36:27 +08:00
|
|
|
|
2021-03-03 01:56:37 +08:00
|
|
|
if (args.Length == RequiredAndOptionalArgumentsQty)
|
|
|
|
{
|
2021-09-29 18:54:05 +08:00
|
|
|
// open specific window
|
|
|
|
switch (args[(int)Arguments.SettingsWindow])
|
|
|
|
{
|
|
|
|
case "Overview": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.GeneralPage); break;
|
|
|
|
case "Awake": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.AwakePage); break;
|
|
|
|
case "ColorPicker": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ColorPickerPage); break;
|
|
|
|
case "FancyZones": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.FancyZonesPage); break;
|
|
|
|
case "Run": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerLauncherPage); break;
|
|
|
|
case "ImageResizer": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ImageResizerPage); break;
|
|
|
|
case "KBM": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.KeyboardManagerPage); break;
|
2021-10-22 20:30:18 +08:00
|
|
|
case "MouseUtils": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.MouseUtilsPage); break;
|
2021-09-29 18:54:05 +08:00
|
|
|
case "PowerRename": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerRenamePage); break;
|
|
|
|
case "FileExplorer": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerPreviewPage); break;
|
|
|
|
case "ShortcutGuide": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ShortcutGuidePage); break;
|
|
|
|
case "VideoConference": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.VideoConferencePage); break;
|
|
|
|
default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
|
|
|
|
}
|
2021-03-03 01:56:37 +08:00
|
|
|
}
|
|
|
|
|
2020-08-18 01:00:56 +08:00
|
|
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
|
|
|
{
|
2020-06-26 07:03:50 +08:00
|
|
|
Environment.Exit(0);
|
|
|
|
});
|
2020-06-11 01:58:34 +08:00
|
|
|
|
2021-02-18 21:11:57 +08:00
|
|
|
ipcmanager = new TwoWayPipeMessageIPCManaged(args[(int)Arguments.SettingsPipeName], args[(int)Arguments.PTPipeName], (string message) =>
|
2020-09-04 16:56:52 +08:00
|
|
|
{
|
|
|
|
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
|
|
|
{
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
|
|
|
|
{
|
|
|
|
IPCMessageReceivedCallback(message);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2020-04-24 08:11:02 +08:00
|
|
|
ipcmanager.Start();
|
2020-04-08 05:19:33 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 08:11:02 +08:00
|
|
|
public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
|
2020-04-08 05:19:33 +08:00
|
|
|
{
|
|
|
|
return ipcmanager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|