From a722ce460c5c7dc0cd4d26cd8e7fb0e8a49f2d4c Mon Sep 17 00:00:00 2001
From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com>
Date: Tue, 5 May 2020 10:02:31 -0700
Subject: [PATCH] [Settings UI] Updated General Settings (#2676)
* updated general settings view
* moved text to string resource
* Update App.xaml.cs
* set run-elevated as a start-up argument
---
PowerToys.sln | 12 +-
.../MainWindow.xaml.cs | 10 ++
.../Program.cs | 14 +-
.../Microsoft.PowerToys.Settings.UI.csproj | 10 +-
.../Strings/en-us/Resources.resw | 20 ++-
.../ViewModels/GeneralViewModel.cs | 152 ++++++++++++++---
.../Views/GeneralPage.xaml | 27 ++-
.../Views/ShellPage.xaml.cs | 30 +++-
...crosoft.PowerToys.Settings.UnitTest.csproj | 3 +-
.../ViewModelTests/General.cs | 161 ++++++++++++++++++
src/runner/settings_window.cpp | 19 +++
11 files changed, 411 insertions(+), 47 deletions(-)
create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs
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}}"/>
+
+
+
+
+
+
+
+
+
-
-
- /// Gets or sets iPC callback function for run on start up.
+ /// Gets or sets iPC default callback function.
///
public static IPCMessageCallback DefaultSndMSGCallback { get; set; }
+ ///
+ /// Gets or sets iPC callback function for restart as admin.
+ ///
+ public static IPCMessageCallback SndRestartAsAdminMsgCallback { get; set; }
+
///
/// Gets view model.
///
public ShellViewModel ViewModel { get; } = new ShellViewModel();
+ public static bool IsElevated { get; set; }
+
///
/// Initializes a new instance of the class.
/// Shell page constructor.
@@ -48,12 +55,31 @@ namespace Microsoft.PowerToys.Settings.UI.Views
}
///
- /// Run on start up callback function elevated initialization.
+ /// Set Default IPC Message callback function.
///
/// delegate function implementation.
public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation)
{
DefaultSndMSGCallback = implmentation;
}
+
+ ///
+ /// Set restart as admin IPC callback function.
+ ///
+ /// delegate function implementation.
+ public void SetRestartAdminSndMessageCallback(IPCMessageCallback implmentation)
+ {
+ SndRestartAsAdminMsgCallback = implmentation;
+ }
+
+ public void SetElevationStatus(bool isElevated)
+ {
+ IsElevated = isElevated;
+ }
+
+ public void Refresh()
+ {
+ shellFrame.Navigate(typeof(GeneralPage));
+ }
}
}
diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj b/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj
index 93166f86bf..f07b3b79e1 100644
--- a/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj
+++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj
@@ -119,6 +119,7 @@
+
@@ -185,4 +186,4 @@
-->
-
+
\ No newline at end of file
diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs
new file mode 100644
index 0000000000..2695d0e281
--- /dev/null
+++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs
@@ -0,0 +1,161 @@
+using Microsoft.PowerToys.Settings.UI.Lib;
+using Microsoft.PowerToys.Settings.UI.ViewModels;
+using Microsoft.PowerToys.Settings.UI.Views;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace ViewModelTests
+{
+ [TestClass]
+ public class General
+ {
+ [TestInitialize]
+ public void Setup()
+ {
+ // initialize creation of test settings file.
+ GeneralSettings generalSettings = new GeneralSettings();
+ SettingsUtils.SaveSettings(generalSettings.ToJsonString());
+ }
+
+ [TestCleanup]
+ public void CleanUp()
+ {
+ // delete folder created.
+ string generalSettings_file_name = string.Empty;
+ if (SettingsUtils.SettingsFolderExists(generalSettings_file_name))
+ {
+ DeleteFolder(generalSettings_file_name);
+ }
+
+ if (SettingsUtils.SettingsFolderExists(string.Empty))
+ {
+ DeleteFolder(string.Empty);
+ }
+ }
+
+ public void DeleteFolder(string powertoy)
+ {
+ Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
+ }
+
+ [TestMethod]
+ public void IsElevated_ShouldUpdateRunasAdminStatusAttrs_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+
+ string runningAsUserText = "Running as user.";
+ string runningAsAdminText = "Running as Adminstrator.";
+ string runningAsUser_AlwaysRunAsAdminText = "Always run as administrator";
+ string runningAsAdmin_AlwaysRunAsAdminText = "Always run as administrator (Restart as administrator to change this)";
+
+ Assert.AreEqual(runningAsUserText, viewModel.RunningAsAdminText);
+ Assert.AreEqual(runningAsAdmin_AlwaysRunAsAdminText, viewModel.AlwaysRunAsAdminText);
+ Assert.IsFalse(viewModel.IsElevated);
+
+ // Act
+ viewModel.IsElevated = true;
+
+ // Assert
+ Assert.AreEqual(runningAsAdminText, viewModel.RunningAsAdminText);
+ Assert.AreEqual(runningAsUser_AlwaysRunAsAdminText, viewModel.AlwaysRunAsAdminText);
+ Assert.IsTrue(viewModel.IsElevated);
+ }
+
+ [TestMethod]
+ public void Startup_ShouldEnableRunOnStartUp_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+ Assert.IsFalse(viewModel.Startup);
+
+ // Assert
+ ShellPage.DefaultSndMSGCallback = msg =>
+ {
+ OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg);
+ Assert.IsTrue(snd.GeneralSettings.Startup);
+ };
+
+ // act
+ viewModel.Startup = true;
+ }
+
+ [TestMethod]
+ public void RunElevated_ShouldEnableAlwaysRunElevated_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+ Assert.IsFalse(viewModel.RunElevated);
+
+ // Assert
+ ShellPage.DefaultSndMSGCallback = msg =>
+ {
+ OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg);
+ Assert.IsTrue(snd.GeneralSettings.RunElevated);
+ };
+
+ // act
+ viewModel.RunElevated = true;
+ }
+
+ [TestMethod]
+ public void AutoDownloadUpdates_ShouldEnableAutoDownloadUpdates_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+ Assert.IsFalse(viewModel.AutoDownloadUpdates);
+
+ // Assert
+ ShellPage.DefaultSndMSGCallback = msg =>
+ {
+ OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg);
+ Assert.IsTrue(snd.GeneralSettings.AutoDownloadUpdates);
+ };
+
+ // act
+ viewModel.AutoDownloadUpdates = true;
+ }
+
+ [TestMethod]
+ public void IsLightThemeRadioButtonChecked_ShouldThemeToLight_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+ Assert.IsFalse(viewModel.IsLightThemeRadioButtonChecked);
+
+ // Assert
+ ShellPage.DefaultSndMSGCallback = msg =>
+ {
+ OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg);
+ Assert.AreEqual("light", snd.GeneralSettings.Theme);
+ };
+
+ // act
+ viewModel.IsLightThemeRadioButtonChecked = true;
+ }
+
+ [TestMethod]
+ public void IsDarkThemeRadioButtonChecked_ShouldThemeToDark_WhenSuccessful()
+ {
+ // Arrange
+ GeneralViewModel viewModel = new GeneralViewModel();
+ Assert.IsFalse(viewModel.IsDarkThemeRadioButtonChecked);
+
+ // Assert
+ ShellPage.DefaultSndMSGCallback = msg =>
+ {
+ OutGoingGeneralSettings snd = JsonSerializer.Deserialize(msg);
+ Assert.AreEqual("dark", snd.GeneralSettings.Theme);
+ };
+
+ // act
+ viewModel.IsDarkThemeRadioButtonChecked = true;
+ }
+ }
+}
diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp
index e2e1f44d39..112cbf8021 100644
--- a/src/runner/settings_window.cpp
+++ b/src/runner/settings_window.cpp
@@ -14,6 +14,7 @@
#include "restart_elevated.h"
#include
+#include
#define BUFSIZE 1024
@@ -250,6 +251,22 @@ void run_settings_window()
settings_theme = L"dark";
}
+ // Arg 4: settings theme.
+ GeneralSettings save_settings = get_general_settings();
+
+ bool isElevated{ get_general_settings().isElevated };
+ std::wstring settings_elevatedStatus;
+ settings_elevatedStatus = isElevated;
+
+ if (isElevated)
+ {
+ settings_elevatedStatus = L"true";
+ }
+ else
+ {
+ settings_elevatedStatus = L"false";
+ }
+
std::wstring executable_args = L"\"";
executable_args.append(executable_path);
executable_args.append(L"\" ");
@@ -260,6 +277,8 @@ void run_settings_window()
executable_args.append(std::to_wstring(powertoys_pid));
executable_args.append(L" ");
executable_args.append(settings_theme);
+ executable_args.append(L" ");
+ executable_args.append(settings_elevatedStatus);
BOOL process_created = false;
if (is_process_elevated())