Skip to content

Commit

Permalink
fix: Start as Admin Error: Unable to open app when running elevated (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Lavius Motileng committed May 3, 2020
1 parent 8e18104 commit b428fc9
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ public class GeneralSettings
[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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
// 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;

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class SndModuleSettings<T>

public SndModuleSettings()
{

}

public SndModuleSettings(T settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.UI.XamlHost" Version="6.0.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="6.0.0" />
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.Controls" Version="6.0.1" />
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public GeneralViewModel()
}

_startup = GeneralSettingsConfigs.Startup;
_autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
}

private bool _packaged = false;
Expand All @@ -65,6 +66,7 @@ public GeneralViewModel()
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
Expand Down Expand Up @@ -97,6 +99,7 @@ public bool Startup
if (_startup != value)
{
_startup = value;
GeneralSettingsConfigs.Startup = value;
RaisePropertyChanged();
}
}
Expand Down Expand Up @@ -138,6 +141,24 @@ public bool RunElevated
}
}

public bool AutoDownloadUpdates
{
get
{
return _autoDownloadUpdates;
}

set
{
if (_autoDownloadUpdates != value)
{
_autoDownloadUpdates = value;
GeneralSettingsConfigs.AutoDownloadUpdates = value;
RaisePropertyChanged();
}
}
}

public bool IsDarkThemeRadioButtonChecked
{
get
Expand Down Expand Up @@ -211,15 +232,17 @@ private async void CheckForUpdates_Click()
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public PowerPreviewViewModel()
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
{
Expand All @@ -46,13 +46,13 @@ public bool SVGRenderIsEnebled
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
{
Expand All @@ -64,7 +64,7 @@ public bool MDRenderIsEnebled
if (value != _mdRenderIsEnabled)
{
_mdRenderIsEnabled = value;
Settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.Value = value;
Settings.properties.EnableMd.Value = value;
RaisePropertyChanged();
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,31 @@

<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"
Margin="{StaticResource SmallTopMargin}"
Style="{StaticResource AccentButtonStyle}"
Command = "{Binding RestartElevatedButtonEventHandler, Source={StaticResource eventViewModel}}"
/>

</StackPanel>

<StackPanel x:Name="SidePanel"
Expand Down Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="UnitTestApp.xaml.cs">
<DependentUpon>UnitTestApp.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModelTests\PowerPreview.cs" />
<Compile Include="ViewModelTests\ShortcutGuide.cs" />
<Compile Include="ViewModelTests\PowerLauncherViewModelTest.cs" />
</ItemGroup>
Expand Down Expand Up @@ -183,4 +184,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public void CleanUp()
{
DeleteFolder(generalSettings_file_name);
}

if (SettingsUtils.SettingsFolderExists(Module))
{
DeleteFolder(Module);
}
}

public void DeleteFolder(string powertoy)
Expand Down

0 comments on commit b428fc9

Please sign in to comment.