mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
[PT Settings] Rename "Microsoft.PowerToys.Setting.UI.Runner" to "PowerToys.Settings" (#9637)
This commit is contained in:
8
src/settings-ui/PowerToys.Settings/App.xaml
Normal file
8
src/settings-ui/PowerToys.Settings/App.xaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<Application x:Class="PowerToys.Settings.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
15
src/settings-ui/PowerToys.Settings/App.xaml.cs
Normal file
15
src/settings-ui/PowerToys.Settings/App.xaml.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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.Windows;
|
||||
|
||||
namespace PowerToys.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
15
src/settings-ui/PowerToys.Settings/MainWindow.xaml
Normal file
15
src/settings-ui/PowerToys.Settings/MainWindow.xaml
Normal file
@@ -0,0 +1,15 @@
|
||||
<Window x:Class="PowerToys.Settings.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:PowerToys.Settings"
|
||||
xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
|
||||
xmlns:xaml="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
|
||||
mc:Ignorable="d"
|
||||
Title="PowerToys Settings" MinWidth="480" Height="800" Width="1100" Closing="MainWindow_Closing">
|
||||
<Grid>
|
||||
<xaml:WindowsXamlHost InitialTypeName="Microsoft.PowerToys.Settings.UI.Views.ShellPage" ChildChanged="WindowsXamlHost_ChildChanged" />
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
110
src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs
Normal file
110
src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
// 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.Windows;
|
||||
using Microsoft.PowerLauncher.Telemetry;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||
using Windows.Data.Json;
|
||||
|
||||
namespace PowerToys.Settings
|
||||
{
|
||||
// Interaction logic for MainWindow.xaml.
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private bool isOpen = true;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
var bootTime = new System.Diagnostics.Stopwatch();
|
||||
bootTime.Start();
|
||||
|
||||
this.InitializeComponent();
|
||||
bootTime.Stop();
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
|
||||
}
|
||||
|
||||
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
|
||||
{
|
||||
// If sender is null, it could lead to a NullReferenceException. This might occur on restarting as admin (check https://github.com/microsoft/PowerToys/issues/7393 for details)
|
||||
if (sender == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Hook up x:Bind source.
|
||||
WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost;
|
||||
ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage;
|
||||
|
||||
if (shellPage != null)
|
||||
{
|
||||
// send IPC Message
|
||||
ShellPage.SetDefaultSndMessageCallback(msg =>
|
||||
{
|
||||
// IPC Manager is null when launching runner directly
|
||||
Program.GetTwoWayIPCManager()?.Send(msg);
|
||||
});
|
||||
|
||||
// send IPC Message
|
||||
ShellPage.SetRestartAdminSndMessageCallback(msg =>
|
||||
{
|
||||
Program.GetTwoWayIPCManager().Send(msg);
|
||||
System.Windows.Application.Current.Shutdown(); // close application
|
||||
});
|
||||
|
||||
// send IPC Message
|
||||
ShellPage.SetCheckForUpdatesMessageCallback(msg =>
|
||||
{
|
||||
Program.GetTwoWayIPCManager().Send(msg);
|
||||
});
|
||||
|
||||
// receive IPC Message
|
||||
Program.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(Program.IsElevated);
|
||||
ShellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin);
|
||||
shellPage.Refresh();
|
||||
}
|
||||
|
||||
// XAML Islands: If the window is open, explicitly force it to be shown to solve the blank dialog issue https://github.com/microsoft/PowerToys/issues/3384
|
||||
if (isOpen)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
isOpen = false;
|
||||
|
||||
// XAML Islands: If the window is closed while minimized, exit the process. Required to avoid process not terminating issue - https://github.com/microsoft/PowerToys/issues/4430
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
// Run Environment.Exit on a separate task to avoid performance impact
|
||||
System.Threading.Tasks.Task.Run(() => { Environment.Exit(0); });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj
Normal file
87
src/settings-ui/PowerToys.Settings/PowerToys.Settings.csproj
Normal file
@@ -0,0 +1,87 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<StartupObject>PowerToys.Settings.Program</StartupObject>
|
||||
<Authors>Microsoft Corporation</Authors>
|
||||
<Product>PowerToys</Product>
|
||||
<Description>PowerToys Settings UI Runner</Description>
|
||||
<Copyright>Copyright (C) 2020 Microsoft Corporation</Copyright>
|
||||
<Company>Microsoft Corporation</Company>
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
<PackageIconUrl />
|
||||
<RepositoryUrl>https://github.com/microsoft/PowerToys</RepositoryUrl>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<PackageTags>PowerToys</PackageTags>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Version>$(Version).0</Version>
|
||||
<Platforms>x64</Platforms>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<Win32Resource />
|
||||
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
|
||||
<!-- crutkas TODO: added for fallback, may need to be removed for WinUI3 -->
|
||||
<AssetTargetFallback>uap10.0.18362</AssetTargetFallback>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutputPath>..\..\..\$(Platform)\$(Configuration)\Settings</OutputPath>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutputPath>..\..\..\$(Platform)\$(Configuration)\Settings</OutputPath>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\settingsui\Assets\logo.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit.UI.XamlHost" Version="6.1.2" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.Controls" Version="6.1.2" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.1.2" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
|
||||
<Version>3.3.0</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\common\interop\PowerToysInterop.vcxproj" />
|
||||
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/settings-ui/PowerToys.Settings/app.manifest
Normal file
13
src/settings-ui/PowerToys.Settings/app.manifest
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
|
||||
<!-- Windows 10 -->
|
||||
<maxversiontested Id="10.0.18362.0"/>
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
</assembly>
|
||||
BIN
src/settings-ui/PowerToys.Settings/icon.ico
Normal file
BIN
src/settings-ui/PowerToys.Settings/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
Reference in New Issue
Block a user