[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
This commit is contained in:
parent
67b2f28064
commit
a722ce460c
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -221,17 +221,17 @@
|
|||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj">
|
||||
<Project>{b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a}</Project>
|
||||
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -366,7 +366,7 @@
|
|||
<value>Enable PowerRename</value>
|
||||
</data>
|
||||
<data name="RadioButtons_Name_Theme.Header" xml:space="preserve">
|
||||
<value>Theme</value>
|
||||
<value>Choose Settings color</value>
|
||||
</data>
|
||||
<data name="PowerRename_Toggle_EnableOnContextMenu.Header" xml:space="preserve">
|
||||
<value>Show on default context menu</value>
|
||||
|
@ -536,4 +536,22 @@
|
|||
<data name="GeneralPage_ToggleSwitch_RunningAsAdminNote.Text" xml:space="preserve">
|
||||
<value>Currently running as administrator</value>
|
||||
</data>
|
||||
<data name="GeneralPage_ToggleSwitch_RunElevated.Header" xml:space="preserve">
|
||||
<value>Always run as administrator (Restart as administrator to change this)</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_AlwaysRunAsAdminText_IsElevated" xml:space="preserve">
|
||||
<value>Always run as administrator</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_AlwaysRunAsAdminText_IsNotElevated" xml:space="preserve">
|
||||
<value>Always run as administrator (Restart as administrator to change this)</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_Running as Adminstrator_IsNotElevated" xml:space="preserve">
|
||||
<value>Running as user</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_RunningAsAdminText_IsElevated" xml:space="preserve">
|
||||
<value>Running as Adminstrator</value>
|
||||
</data>
|
||||
<data name="String1" xml:space="preserve">
|
||||
<value />
|
||||
</data>
|
||||
</root>
|
|
@ -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<GeneralSettings>(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,27 @@
|
|||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/>
|
||||
|
||||
<TextBlock Text="{Binding Mode=TwoWay, Path=RunningAsAdminText, Source={StaticResource eventViewModel}}"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"
|
||||
Margin="{StaticResource MediumTopMargin}"/>
|
||||
|
||||
<ToggleSwitch Margin="{StaticResource SmallTopMargin}"
|
||||
Header="{Binding Mode=TwoWay, Path=AlwaysRunAsAdminText, Source={StaticResource eventViewModel}}"
|
||||
IsEnabled="{Binding Mode=TwoWay, Path=IsElevated, Source={StaticResource eventViewModel}}"
|
||||
IsOn="{Binding Mode=TwoWay, Path=RunElevated, Source={StaticResource eventViewModel}}"/>
|
||||
|
||||
<Button x:Uid="GeneralPage_RestartAsAdmin_Button"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
Style="{StaticResource AccentButtonStyle}"
|
||||
Command = "{Binding RestartElevatedButtonEventHandler, Source={StaticResource eventViewModel}}"
|
||||
IsEnabled="{Binding Mode=TwoWay, Path=IsAdminButtonEnabled, Source={StaticResource eventViewModel}}"
|
||||
/>
|
||||
|
||||
|
||||
<TextBlock x:Uid="Appearancce_GroupSettings"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"
|
||||
Margin="{StaticResource MediumTopMargin}"/>
|
||||
|
||||
<muxc:RadioButtons x:Uid="RadioButtons_Name_Theme" Margin="{StaticResource SmallTopMargin}">
|
||||
<RadioButton x:Uid="GeneralPage_Radio_Theme_Dark"
|
||||
Content="Dark"
|
||||
|
@ -71,12 +92,6 @@
|
|||
Content="System default"
|
||||
IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
|
||||
</muxc:RadioButtons>
|
||||
|
||||
<Button x:Uid="GeneralPage_RestartAsAdmin_Button"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
Style="{StaticResource AccentButtonStyle}"
|
||||
Command = "{Binding RestartElevatedButtonEventHandler, Source={StaticResource eventViewModel}}"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="SidePanel"
|
||||
|
|
|
@ -24,15 +24,22 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||
public static ShellPage ShellHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets iPC callback function for run on start up.
|
||||
/// Gets or sets iPC default callback function.
|
||||
/// </summary>
|
||||
public static IPCMessageCallback DefaultSndMSGCallback { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets iPC callback function for restart as admin.
|
||||
/// </summary>
|
||||
public static IPCMessageCallback SndRestartAsAdminMsgCallback { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets view model.
|
||||
/// </summary>
|
||||
public ShellViewModel ViewModel { get; } = new ShellViewModel();
|
||||
|
||||
public static bool IsElevated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShellPage"/> class.
|
||||
/// Shell page constructor.
|
||||
|
@ -48,12 +55,31 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run on start up callback function elevated initialization.
|
||||
/// Set Default IPC Message callback function.
|
||||
/// </summary>
|
||||
/// <param name="implmentation">delegate function implementation.</param>
|
||||
public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation)
|
||||
{
|
||||
DefaultSndMSGCallback = implmentation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set restart as admin IPC callback function.
|
||||
/// </summary>
|
||||
/// <param name="implmentation">delegate function implementation.</param>
|
||||
public void SetRestartAdminSndMessageCallback(IPCMessageCallback implmentation)
|
||||
{
|
||||
SndRestartAsAdminMsgCallback = implmentation;
|
||||
}
|
||||
|
||||
public void SetElevationStatus(bool isElevated)
|
||||
{
|
||||
IsElevated = isElevated;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
shellFrame.Navigate(typeof(GeneralPage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ViewModelTests\General.cs" />
|
||||
<Compile Include="ModelsTests\HelperTest.cs" />
|
||||
<Compile Include="ViewModelTests\ImageResizer.cs" />
|
||||
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
||||
|
@ -185,4 +186,4 @@
|
|||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
|
@ -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<OutGoingGeneralSettings>(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<OutGoingGeneralSettings>(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<OutGoingGeneralSettings>(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<OutGoingGeneralSettings>(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<OutGoingGeneralSettings>(msg);
|
||||
Assert.AreEqual("dark", snd.GeneralSettings.Theme);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.IsDarkThemeRadioButtonChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
#include "restart_elevated.h"
|
||||
|
||||
#include <common/json.h>
|
||||
#include <common\settings_helpers.cpp>
|
||||
|
||||
#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())
|
||||
|
|
Loading…
Reference in a new issue