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
This commit is contained in:
Lavius Motileng
2020-05-03 03:17:06 -07:00
committed by GitHub
parent 8e18104f38
commit b428fc97e9
17 changed files with 208 additions and 37 deletions

View File

@@ -524,4 +524,16 @@
<data name="On.Content" xml:space="preserve">
<value>On</value>
</data>
<data name="GeneralPage_ToggleSwitch_AlwaysRunElevated.Header" xml:space="preserve">
<value>Always Run as Admin</value>
</data>
<data name="GeneralPage_ToggleSwitch_AlwaysRunElevated_Link.Content" xml:space="preserve">
<value>Learn about Admin mode</value>
</data>
<data name="GeneralPage_ToggleSwitch_AutoDownloadUpdates.Header" xml:space="preserve">
<value>Download updates automatically</value>
</data>
<data name="GeneralPage_ToggleSwitch_RunningAsAdminNote.Text" xml:space="preserve">
<value>Currently running as administrator</value>
</data>
</root>

View File

@@ -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<GeneralSettings>(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());
}
}
}

View File

@@ -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();
}
}

View File

@@ -52,20 +52,24 @@
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_RunAtStartUp"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=Startup}"/>
IsOn="{Binding Mode=TwoWay, Path=Startup, Source={StaticResource eventViewModel}}"/>
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_AutoDownloadUpdates"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/>
<muxc:RadioButtons x:Uid="RadioButtons_Name_Theme" Margin="{StaticResource SmallTopMargin}">
<RadioButton x:Uid="GeneralPage_Radio_Theme_Dark"
Content="Dark"
IsChecked="{ Binding Mode=TwoWay, Path=IsDarkThemeRadioButtonChecked}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsDarkThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
<RadioButton x:Uid="GeneralPage_Radio_Theme_Light"
Content="Light"
IsChecked="{ Binding Mode=TwoWay, Path=IsLightThemeRadioButtonChecked}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsLightThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
<RadioButton x:Uid="GeneralPage_Radio_Theme_Default"
Content="System default"
IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked}"/>
IsChecked="{ Binding Mode=TwoWay, Path=IsSystemThemeRadioButtonChecked, Source={StaticResource eventViewModel}}"/>
</muxc:RadioButtons>
<Button x:Uid="GeneralPage_RestartAsAdmin_Button"
@@ -73,7 +77,6 @@
Style="{StaticResource AccentButtonStyle}"
Command = "{Binding RestartElevatedButtonEventHandler, Source={StaticResource eventViewModel}}"
/>
</StackPanel>
<StackPanel x:Name="SidePanel"
@@ -108,8 +111,10 @@
NavigateUri=" http://go.microsoft.com/fwlink/?LinkId=521839" />
<HyperlinkButton x:Uid="OpenSource_Notice"
NavigateUri="https://github.com/microsoft/PowerToys/blob/master/NOTICE.md"
/>
NavigateUri="https://github.com/microsoft/PowerToys/blob/master/NOTICE.md"/>
<HyperlinkButton x:Uid="GeneralPage_ToggleSwitch_AlwaysRunElevated_Link"
NavigateUri="https://github.com/microsoft/PowerToys/blob/master/doc/devdocs/run-as-admin-detection.md"/>
</StackPanel>
</Grid>
</Page>

View File

@@ -46,11 +46,11 @@
<ToggleSwitch x:Uid="FileEplorerPreview_ToggleSwitch_Preview_SVG"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=SVGRenderIsEnebled}" />
IsOn="{Binding Mode=TwoWay, Path=SVGRenderIsEnabled}" />
<ToggleSwitch x:Uid="FileEplorerPreview_ToggleSwitch_Preview_MD"
Margin="{StaticResource SmallTopMargin}"
IsOn="{Binding Mode=TwoWay, Path=MDRenderIsEnebled}" />
IsOn="{Binding Mode=TwoWay, Path=MDRenderIsEnabled}" />
</StackPanel>
<StackPanel x:Name="SidePanel"