diff --git a/PowerToys.sln b/PowerToys.sln index 0f868736b8..ad2e5ddc68 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -778,15 +778,13 @@ Global {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Release|x64.ActiveCfg = Release|x64 {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Release|x64.Build.0 = Release|x64 {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}.Release|x86.ActiveCfg = Release|x64 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|ARM.ActiveCfg = Debug|Win32 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|ARM64.ActiveCfg = Debug|Win32 + {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|ARM.ActiveCfg = Debug|x64 + {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|ARM64.ActiveCfg = Debug|x64 {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x64.ActiveCfg = Debug|x64 {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x64.Build.0 = Debug|x64 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x86.ActiveCfg = Debug|Win32 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x86.Build.0 = Debug|Win32 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x86.Deploy.0 = Debug|Win32 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|ARM.ActiveCfg = Release|Win32 - {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|ARM64.ActiveCfg = Release|Win32 + {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Debug|x86.ActiveCfg = Debug|x64 + {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|ARM.ActiveCfg = Release|x64 + {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|ARM64.ActiveCfg = Release|x64 {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x64.ActiveCfg = Release|x64 {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x64.Build.0 = Release|x64 {A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x86.ActiveCfg = Release|x64 diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs index 03705b6326..3eb5d43604 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs @@ -31,6 +31,16 @@ namespace Microsoft.PowerToys.Settings.UI.Runner { Program.GetTwoWayIPCManager().Send(msg); }); + + // send IPC Message + shellPage.SetRestartAdminSndMessageCallback(msg => + { + Program.GetTwoWayIPCManager().Send(msg); + System.Windows.Application.Current.Shutdown(); // close application + }); + + shellPage.SetElevationStatus(Program.IsElevated); + shellPage.Refresh(); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/Program.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/Program.cs index c5e2a43c5c..a462aceb4a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/Program.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/Program.cs @@ -5,6 +5,7 @@ using System; using System.Windows; using interop; +using Windows.UI.Popups; namespace Microsoft.PowerToys.Settings.UI.Runner { @@ -13,6 +14,8 @@ namespace Microsoft.PowerToys.Settings.UI.Runner // Create an instance of the IPC wrapper. private static TwoWayPipeMessageIPCManaged ipcmanager; + public static bool IsElevated { get; set; } + [STAThread] public static void Main(string[] args) { @@ -21,8 +24,17 @@ namespace Microsoft.PowerToys.Settings.UI.Runner App app = new App(); app.InitializeComponent(); - if (args.Length > 1) + if (args.Length > 3) { + if (args[4] == "true") + { + IsElevated = true; + } + else + { + IsElevated = false; + } + ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null); ipcmanager.Start(); app.Run(); diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj index 136f08e92a..6a00164230 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj @@ -221,17 +221,17 @@ MSBuild:Compile + + + StyleCop.json + + {b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a} Microsoft.PowerToys.Settings.UI.Lib - - - StyleCop.json - - 14.0 diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index 2f6e29e84c..792170b70b 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -366,7 +366,7 @@ Enable PowerRename - Theme + Choose Settings color Show on default context menu @@ -536,4 +536,22 @@ Currently running as administrator + + Always run as administrator (Restart as administrator to change this) + + + Always run as administrator + + + Always run as administrator (Restart as administrator to change this) + + + Running as user + + + Running as Adminstrator + + + + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs index 6e487fb548..b9b7969b58 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs @@ -10,8 +10,9 @@ using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.ViewModels.Commands; using Microsoft.PowerToys.Settings.UI.Views; +using Windows.ApplicationModel.Resources; using Microsoft.PowerToys.Settings.UI.Lib.Utilities; -using Windows.Data.Html; +using Windows.Data.Html; using Windows.System; using Windows.UI.Popups; using Windows.UI.Xaml; @@ -26,6 +27,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels public ButtonClickCommand RestartElevatedButtonEventHandler { get; set; } + private ResourceLoader loader = ResourceLoader.GetForCurrentView(); + public GeneralViewModel() { this.CheckFoUpdatesEventHandler = new ButtonClickCommand(CheckForUpdates_Click); @@ -35,17 +38,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { GeneralSettingsConfigs = SettingsUtils.GetSettings(string.Empty); - if (Helper.CompareVersions(GeneralSettingsConfigs.PowertoysVersion, Helper.GetProductVersion()) < 0) - { - // Update settings - GeneralSettingsConfigs.PowertoysVersion = Helper.GetProductVersion(); - SettingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty); + if (Helper.CompareVersions(GeneralSettingsConfigs.PowertoysVersion, Helper.GetProductVersion()) < 0) + { + // Update settings + GeneralSettingsConfigs.PowertoysVersion = Helper.GetProductVersion(); + SettingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty); } } catch (FormatException e) - { - // If there is an issue with the version number format, don't migrate settings. - Debug.WriteLine(e.Message); + { + // If there is an issue with the version number format, don't migrate settings. + Debug.WriteLine(e.Message); } catch { @@ -57,20 +60,43 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { case "light": _isLightThemeRadioButtonChecked = true; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + } + catch + { + } + break; case "dark": _isDarkThemeRadioButtonChecked = true; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + } + catch + { + } + break; case "system": _isSystemThemeRadioButtonChecked = true; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + } + catch + { + } + break; } _startup = GeneralSettingsConfigs.Startup; _autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates; + _isElevated = ShellPage.IsElevated; + _runElevated = GeneralSettingsConfigs.RunElevated; } private bool _packaged = false; @@ -100,6 +126,26 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public string AlwaysRunAsAdminText + { + get + { + if (IsElevated) + { + return loader.GetString("GeneralSettings_AlwaysRunAsAdminText_IsElevated"); + } + else + { + return loader.GetString("GeneralSettings_AlwaysRunAsAdminText_IsNotElevated"); + } + } + + set + { + OnPropertyChanged("AlwaysRunAsAdminText"); + } + } + // Gets or sets a value indicating whether run powertoys on start-up. public bool Startup { @@ -119,6 +165,26 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public string RunningAsAdminText + { + get + { + if (!IsElevated) + { + return loader.GetString("GeneralSettings_Running as Adminstrator_IsNotElevated"); + } + else + { + return loader.GetString("GeneralSettings_RunningAsAdminText_IsElevated"); + } + } + + set + { + OnPropertyChanged("RunningAsAdminText"); + } + } + // Gets or sets a value indicating whether the powertoy elevated. public bool IsElevated { @@ -132,11 +198,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (_isElevated != value) { _isElevated = value; - RaisePropertyChanged(); + OnPropertyChanged("IsElevated"); + OnPropertyChanged("IsAdminButtonEnabled"); + OnPropertyChanged("AlwaysRunAsAdminText"); + OnPropertyChanged("RunningAsAdminText"); } } } + public bool IsAdminButtonEnabled + { + get + { + return !IsElevated; + } + + set + { + OnPropertyChanged("IsAdminButtonEnabled"); + } + } + // Gets or sets a value indicating whether powertoys should run elevated. public bool RunElevated { @@ -150,6 +232,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (_runElevated != value) { _runElevated = value; + GeneralSettingsConfigs.RunElevated = value; RaisePropertyChanged(); } } @@ -186,7 +269,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { GeneralSettingsConfigs.Theme = "dark"; _isDarkThemeRadioButtonChecked = value; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark; + } + catch + { + } + RaisePropertyChanged(); } } @@ -205,7 +295,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { GeneralSettingsConfigs.Theme = "light"; _isLightThemeRadioButtonChecked = value; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light; + } + catch + { + } + RaisePropertyChanged(); } } @@ -224,18 +321,25 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { GeneralSettingsConfigs.Theme = "system"; _isSystemThemeRadioButtonChecked = value; - ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + try + { + ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default; + } + catch + { + } + RaisePropertyChanged(); } } } - public string PowerToysVersion - { - get - { - return Helper.GetProductVersion(); - } + public string PowerToysVersion + { + get + { + return Helper.GetProductVersion(); + } } public void RaisePropertyChanged([CallerMemberName] string propertyName = null) @@ -262,9 +366,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings); - if (ShellPage.DefaultSndMSGCallback != null) + if (ShellPage.SndRestartAsAdminMsgCallback != null) { - ShellPage.DefaultSndMSGCallback(customaction.ToString()); + ShellPage.SndRestartAsAdminMsgCallback(customaction.ToString()); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml index 925b9dc95b..2ce666bc13 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml @@ -58,6 +58,27 @@ Margin="{StaticResource SmallTopMargin}" IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/> + + + + +