From b428fc97e97e455cf5deb73a98c9c496b1369d3e Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Sun, 3 May 2020 03:17:06 -0700 Subject: [PATCH] fix: Start as Admin Error: Unable to open app when running elevated (#2411) * fixed run-elevated error and powerpreview settings not working * removed EXTENDED_STARTUPINFO_PRESENT flag * removed test string * Update Microsoft.PowerToys.Settings.UnitTest.csproj * Rename PowerLauncher.cs to PowerLauncherViewModelTest.cs --- .../GeneralSettings.cs | 8 ++ .../GeneralSettingsCustomAction.cs | 25 ++++++ .../PowerPreviewProperties.cs | 13 ++- .../SndModuleSettings.cs | 1 - .../SndPowerPreviewSettings.cs | 10 ++- ...rosoft.PowerToys.Settings.UI.Runner.csproj | 1 - .../Strings/en-us/Resources.resw | 12 +++ .../ViewModels/GeneralViewModel.cs | 29 ++++++- .../ViewModels/PowerPreviewViewModel.cs | 12 +-- .../Views/GeneralPage.xaml | 19 ++-- .../Views/PowerPreviewPage.xaml | 4 +- ...crosoft.PowerToys.Settings.UnitTest.csproj | 3 +- .../ViewModelTests/ImageResizer.cs | 5 ++ .../ViewModelTests/PowerPreview.cs | 86 +++++++++++++++++++ .../ViewModelTests/ShortcutGuide.cs | 13 ++- src/runner/settings_window.cpp | 3 +- src/settings/main.cpp | 1 - 17 files changed, 208 insertions(+), 37 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettingsCustomAction.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs index d8041639d9..8250d947e1 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs @@ -41,19 +41,27 @@ namespace Microsoft.PowerToys.Settings.UI.Lib [JsonPropertyName("powertoys_version")] public string PowertoysVersion { get; set; } + [JsonPropertyName("action_name")] + public string CustomActionName { get; set; } + [JsonPropertyName("enabled")] public EnabledModules Enabled { get; set; } + [JsonPropertyName("download_updates_automatically")] + public bool AutoDownloadUpdates { get; set; } + public GeneralSettings() { this.Packaged = false; this.Startup = false; this.IsAdmin = false; this.IsElevated = false; + this.AutoDownloadUpdates = false; this.Theme = "system"; this.SystemTheme = "light"; this.PowertoysVersion = "v0.15.3"; this.Enabled = new EnabledModules(); + this.CustomActionName = string.Empty; } // converts the current to a json string. diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettingsCustomAction.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettingsCustomAction.cs new file mode 100644 index 0000000000..18d28daa01 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettingsCustomAction.cs @@ -0,0 +1,25 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class GeneralSettingsCustomAction + { + [JsonPropertyName("action")] + public OutGoingGeneralSettings GeneralSettingsAction { get; set; } + + public GeneralSettingsCustomAction() + { + } + + public GeneralSettingsCustomAction(OutGoingGeneralSettings action) + { + GeneralSettingsAction = action; + } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewProperties.cs index 34e3797f48..ff9438075c 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewProperties.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewProperties.cs @@ -2,9 +2,6 @@ // 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.Collections.Generic; -using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -12,14 +9,16 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { public class PowerPreviewProperties { - public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; } + [JsonPropertyName("svg-previewer-toggle-setting")] + public BoolProperty EnableSvg { get; set; } - public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; } + [JsonPropertyName("md-previewer-toggle-setting")] + public BoolProperty EnableMd { get; set; } public PowerPreviewProperties() { - IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new BoolProperty(); - PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new BoolProperty(); + EnableSvg = new BoolProperty(); + EnableMd = new BoolProperty(); } public override string ToString() diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs index ef067090ba..aed13e7d0d 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs @@ -15,7 +15,6 @@ namespace Microsoft.PowerToys.Settings.UI.Lib public SndModuleSettings() { - } public SndModuleSettings(T settings) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndPowerPreviewSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndPowerPreviewSettings.cs index dcd4661c4b..c0decebfe2 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndPowerPreviewSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndPowerPreviewSettings.cs @@ -12,12 +12,16 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { public class SndPowerPreviewSettings { - [JsonPropertyName("File Explorer Preview")] - public PowerPreviewSettings File_Explorer_Preview { get; set; } + [JsonPropertyName("File Explorer")] + public PowerPreviewSettings FileExplorerPreviewSettings { get; set; } + + public SndPowerPreviewSettings() + { + } public SndPowerPreviewSettings(PowerPreviewSettings settings) { - File_Explorer_Preview = settings; + FileExplorerPreviewSettings = settings; } public string ToJsonString() diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/Microsoft.PowerToys.Settings.UI.Runner.csproj b/src/core/Microsoft.PowerToys.Settings.UI.Runner/Microsoft.PowerToys.Settings.UI.Runner.csproj index 5eea92d8c5..619915a358 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/Microsoft.PowerToys.Settings.UI.Runner.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/Microsoft.PowerToys.Settings.UI.Runner.csproj @@ -57,7 +57,6 @@ - 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 19229d6c69..2f6e29e84c 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 @@ -524,4 +524,16 @@ On + + Always Run as Admin + + + Learn about Admin mode + + + Download updates automatically + + + Currently running as administrator + \ 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 5ab16a997b..5b62a3ef43 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/GeneralViewModel.cs @@ -56,6 +56,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } _startup = GeneralSettingsConfigs.Startup; + _autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates; } private bool _packaged = false; @@ -65,6 +66,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels private bool _isDarkThemeRadioButtonChecked = false; private bool _isLightThemeRadioButtonChecked = false; private bool _isSystemThemeRadioButtonChecked = false; + private bool _autoDownloadUpdates = false; // Gets or sets a value indicating whether packaged. public bool Packaged @@ -97,6 +99,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (_startup != value) { _startup = value; + GeneralSettingsConfigs.Startup = value; RaisePropertyChanged(); } } @@ -138,6 +141,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public bool AutoDownloadUpdates + { + get + { + return _autoDownloadUpdates; + } + + set + { + if (_autoDownloadUpdates != value) + { + _autoDownloadUpdates = value; + GeneralSettingsConfigs.AutoDownloadUpdates = value; + RaisePropertyChanged(); + } + } + } + public bool IsDarkThemeRadioButtonChecked { get @@ -211,15 +232,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/PowerToys/releases")); } - private void Restart_Elevated() + public void Restart_Elevated() { GeneralSettings settings = SettingsUtils.GetSettings(string.Empty); - settings.RunElevated = true; + settings.CustomActionName = "restart_elevation"; + OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); + GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings); if (ShellPage.DefaultSndMSGCallback != null) { - ShellPage.DefaultSndMSGCallback(outsettings.ToString()); + ShellPage.DefaultSndMSGCallback(customaction.ToString()); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs index 9e88b0dbed..fbd6fb5133 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -27,14 +27,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); } - this._svgRenderIsEnabled = Settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.Value; - this._mdRenderIsEnabled = Settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.Value; + this._svgRenderIsEnabled = Settings.properties.EnableSvg.Value; + this._mdRenderIsEnabled = Settings.properties.EnableMd.Value; } private bool _svgRenderIsEnabled = false; private bool _mdRenderIsEnabled = false; - public bool SVGRenderIsEnebled + public bool SVGRenderIsEnabled { get { @@ -46,13 +46,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (value != _svgRenderIsEnabled) { _svgRenderIsEnabled = value; - Settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.Value = value; + Settings.properties.EnableSvg.Value = value; RaisePropertyChanged(); } } } - public bool MDRenderIsEnebled + public bool MDRenderIsEnabled { get { @@ -64,7 +64,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels if (value != _mdRenderIsEnabled) { _mdRenderIsEnabled = value; - Settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.Value = value; + Settings.properties.EnableMd.Value = value; RaisePropertyChanged(); } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml index 9ca3684c49..ab43e216f7 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml @@ -52,20 +52,24 @@ + IsOn="{Binding Mode=TwoWay, Path=Startup, Source={StaticResource eventViewModel}}"/> + + + IsChecked="{ Binding Mode=TwoWay, Path=IsDarkThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/> + IsChecked="{ Binding Mode=TwoWay, Path=IsLightThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/> + IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>