Use it in runner - POC
This commit is contained in:
parent
5fce8863d8
commit
85922cef2c
|
@ -277,7 +277,7 @@ void run_settings_window(bool show_oobe_window, std::optional<std::wstring> sett
|
||||||
// Arg 1: executable path.
|
// Arg 1: executable path.
|
||||||
std::wstring executable_path = get_module_folderpath();
|
std::wstring executable_path = get_module_folderpath();
|
||||||
|
|
||||||
executable_path.append(L"\\Settings\\PowerToys.Settings.exe");
|
executable_path.append(L"\\SettingsUI\\net5.0-windows10.0.19041.0\\Microsoft.PowerToys.Settings.UI.WinUI3.exe");
|
||||||
|
|
||||||
// Args 2,3: pipe server. Generate unique names for the pipes, if getting a UUID is possible.
|
// Args 2,3: pipe server. Generate unique names for the pipes, if getting a UUID is possible.
|
||||||
std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");
|
std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");
|
||||||
|
|
|
@ -4,6 +4,11 @@ using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
|
||||||
// TODO(stefan)
|
// TODO(stefan)
|
||||||
using WindowsUI = Windows.UI;
|
using WindowsUI = Windows.UI;
|
||||||
|
using interop;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.WinUI3.Views;
|
||||||
|
|
||||||
// To learn more about WinUI, the WinUI project structure,
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||||
|
@ -15,6 +20,35 @@ namespace Microsoft.PowerToys.Settings.UI.WinUI3
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
private enum Arguments
|
||||||
|
{
|
||||||
|
PTPipeName = 1,
|
||||||
|
SettingsPipeName,
|
||||||
|
PTPid,
|
||||||
|
Theme, // used in the old settings
|
||||||
|
ElevatedStatus,
|
||||||
|
IsUserAdmin,
|
||||||
|
ShowOobeWindow,
|
||||||
|
SettingsWindow,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quantity of arguments
|
||||||
|
private const int RequiredArgumentsQty = 8;
|
||||||
|
private const int RequiredAndOptionalArgumentsQty = 9;
|
||||||
|
|
||||||
|
// 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; }
|
||||||
|
public bool ShowOobe { get; set; }
|
||||||
|
public Type StartupPage { get; set; } = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.GeneralPage);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the singleton application object. This is the first line of authored code
|
/// Initializes the singleton application object. This is the first line of authored code
|
||||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
|
@ -36,6 +70,70 @@ namespace Microsoft.PowerToys.Settings.UI.WinUI3
|
||||||
//m_window.SetTitleBar(m_window.CustomTitleBar); // This should work according to docs, but it doesn't.... So disabling for now together with ExtendsContentIntoTitleBar
|
//m_window.SetTitleBar(m_window.CustomTitleBar); // This should work according to docs, but it doesn't.... So disabling for now together with ExtendsContentIntoTitleBar
|
||||||
m_window.Title = "PowerToys Settings";
|
m_window.Title = "PowerToys Settings";
|
||||||
m_window.Activate();
|
m_window.Activate();
|
||||||
|
|
||||||
|
var cmdArgs = Environment.GetCommandLineArgs();
|
||||||
|
if (cmdArgs != null && cmdArgs.Length >= RequiredArgumentsQty)
|
||||||
|
{
|
||||||
|
_ = int.TryParse(cmdArgs[(int)Arguments.PTPid], out int powerToysPID);
|
||||||
|
PowerToysPID = powerToysPID;
|
||||||
|
|
||||||
|
IsElevated = cmdArgs[(int)Arguments.ElevatedStatus] == "true";
|
||||||
|
IsUserAnAdmin = cmdArgs[(int)Arguments.IsUserAdmin] == "true";
|
||||||
|
ShowOobe = cmdArgs[(int)Arguments.ShowOobeWindow] == "true";
|
||||||
|
|
||||||
|
if (cmdArgs.Length == RequiredAndOptionalArgumentsQty)
|
||||||
|
{
|
||||||
|
// open specific window
|
||||||
|
switch (cmdArgs[(int)Arguments.SettingsWindow])
|
||||||
|
{
|
||||||
|
case "Overview": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.GeneralPage); break;
|
||||||
|
case "Awake": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.AwakePage); break;
|
||||||
|
case "ColorPicker": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.ColorPickerPage); break;
|
||||||
|
case "FancyZones": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.FancyZonesPage); break;
|
||||||
|
case "Run": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.PowerLauncherPage); break;
|
||||||
|
case "ImageResizer": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.ImageResizerPage); break;
|
||||||
|
case "KBM": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.KeyboardManagerPage); break;
|
||||||
|
case "MouseUtils": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.MouseUtilsPage); break;
|
||||||
|
case "PowerRename": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.PowerRenamePage); break;
|
||||||
|
case "FileExplorer": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.PowerPreviewPage); break;
|
||||||
|
case "ShortcutGuide": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.ShortcutGuidePage); break;
|
||||||
|
case "VideoConference": StartupPage = typeof(Microsoft.PowerToys.Settings.UI.WinUI3.Views.VideoConferencePage); break;
|
||||||
|
default: break;// TODO(stefan): This crashes Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
|
||||||
|
}
|
||||||
|
// m_window.Asd().Text = StartupPage.ToString() + " " + cmdArgs[(int)Arguments.SettingsWindow];
|
||||||
|
}
|
||||||
|
|
||||||
|
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcmanager = new TwoWayPipeMessageIPCManaged(cmdArgs[(int)Arguments.SettingsPipeName], cmdArgs[(int)Arguments.PTPipeName], (string message) =>
|
||||||
|
{
|
||||||
|
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
||||||
|
{
|
||||||
|
m_window.DispatcherQueue.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
// TODO(stefan): not sure if this is correct
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsDarkTheme()
|
public static bool IsDarkTheme()
|
||||||
|
@ -46,7 +144,7 @@ namespace Microsoft.PowerToys.Settings.UI.WinUI3
|
||||||
return selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && uiTheme == "#FF000000");
|
return selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && uiTheme == "#FF000000");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Window m_window;
|
private MainWindow m_window;
|
||||||
private static ISettingsUtils settingsUtils = new SettingsUtils();
|
private static ISettingsUtils settingsUtils = new SettingsUtils();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,6 @@
|
||||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Margin="12,0,0,0" Text="PowerToys" />
|
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Margin="12,0,0,0" Text="PowerToys" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>-->
|
</Grid>-->
|
||||||
<local:ShellPage Grid.Row="1"/>
|
<local:ShellPage Grid.Row="1" x:Name="shellPage"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.PowerToys.Settings.UI.WinUI3.Views;
|
||||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Data;
|
|
||||||
using Microsoft.UI.Xaml.Input;
|
|
||||||
using Microsoft.UI.Xaml.Media;
|
|
||||||
using Microsoft.UI.Xaml.Navigation;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using Windows.Data.Json;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
|
||||||
using Windows.Foundation;
|
|
||||||
using Windows.Foundation.Collections;
|
|
||||||
|
|
||||||
// To learn more about WinUI, the WinUI project structure,
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||||
|
@ -26,6 +17,61 @@ namespace Microsoft.PowerToys.Settings.UI.WinUI3
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// TODO(stefan)
|
||||||
|
// isOpen = false;
|
||||||
|
Environment.Exit(0);
|
||||||
|
// System.Windows.Application.Current.Shutdown(); // close application
|
||||||
|
});
|
||||||
|
|
||||||
|
// send IPC Message
|
||||||
|
ShellPage.SetCheckForUpdatesMessageCallback(msg =>
|
||||||
|
{
|
||||||
|
App.GetTwoWayIPCManager()?.Send(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// open oobe
|
||||||
|
ShellPage.SetOpenOobeCallback(() =>
|
||||||
|
{
|
||||||
|
/* var oobe = new OobeWindow();
|
||||||
|
oobe.Show();
|
||||||
|
*/ });
|
||||||
|
|
||||||
|
// 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShellPage.SetElevationStatus(App.IsElevated);
|
||||||
|
ShellPage.SetIsUserAnAdmin(App.IsUserAnAdmin);
|
||||||
|
shellPage.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<UseWinUI>true</UseWinUI>
|
<UseWinUI>true</UseWinUI>
|
||||||
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
||||||
<WindowsPackageType>None</WindowsPackageType>
|
<WindowsPackageType>None</WindowsPackageType>
|
||||||
|
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
|
||||||
<OutputPath></OutputPath>
|
<OutputPath></OutputPath>
|
||||||
|
|
BIN
src/settings-ui/Microsoft.PowerToys.Settings.UI.WinUI3/icon.ico
Normal file
BIN
src/settings-ui/Microsoft.PowerToys.Settings.UI.WinUI3/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
Loading…
Reference in a new issue