Autoupdate option visible only for administrators group (#2945)

* Added isAdmin value to Settings.UI. Changed elevation check to user group check for AutoDownload toggle
This commit is contained in:
Yevhenii Holovachov
2020-05-14 12:36:27 +03:00
committed by GitHub
parent 3dc61962de
commit a13c8cb71e
7 changed files with 52 additions and 9 deletions

View File

@@ -41,6 +41,7 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
});
shellPage.SetElevationStatus(Program.IsElevated);
shellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin);
shellPage.Refresh();
}
}

View File

@@ -11,11 +11,16 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
{
public class Program
{
// Quantity of arguments
private const int ArgumentsQty = 5;
// Create an instance of the IPC wrapper.
private static TwoWayPipeMessageIPCManaged ipcmanager;
public static bool IsElevated { get; set; }
public static bool IsUserAnAdmin { get; set; }
[STAThread]
public static void Main(string[] args)
{
@@ -24,7 +29,7 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
App app = new App();
app.InitializeComponent();
if (args.Length > 3)
if (args.Length >= ArgumentsQty)
{
if (args[4] == "true")
{
@@ -35,6 +40,15 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
IsElevated = false;
}
if (args[5] == "true")
{
IsUserAnAdmin = true;
}
else
{
IsUserAnAdmin = false;
}
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
ipcmanager.Start();
app.Run();

View File

@@ -8,10 +8,10 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
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.System;
using Windows.UI.Popups;
@@ -97,12 +97,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
_isElevated = ShellPage.IsElevated;
_runElevated = GeneralSettingsConfigs.RunElevated;
_isAdmin = ShellPage.IsUserAnAdmin;
}
private bool _packaged = false;
private bool _startup = false;
private bool _isElevated = false;
private bool _runElevated = false;
private bool _isAdmin = false;
private bool _isDarkThemeRadioButtonChecked = false;
private bool _isLightThemeRadioButtonChecked = false;
private bool _isSystemThemeRadioButtonChecked = false;
@@ -218,6 +220,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
// Gets a value indicating whether the user is part of administrators group.
public bool IsAdmin
{
get
{
return _isAdmin;
}
}
public bool AutoDownloadUpdates
{
get

View File

@@ -13,6 +13,7 @@
<Page.Resources>
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible"/>
<converters:BoolToVisibilityConverter x:Key="VisibleIfTrueConverter"/>
<viewModel:GeneralViewModel x:Key="eventViewModel"/>
</Page.Resources>
@@ -119,14 +120,9 @@
Command="{Binding CheckFoUpdatesEventHandler, Source={StaticResource eventViewModel}}"
/>
<TextBlock x:Uid="General_RunAsAdminRequired"
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}"
Visibility="{Binding Mode=TwoWay, Path=IsElevated, Source={StaticResource eventViewModel}, Converter={StaticResource BoolToVisibilityConverter}}"
Margin="0,24,0,-20" />
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_AutoDownloadUpdates"
Margin="{StaticResource MediumTopMargin}"
IsEnabled="{Binding Mode=TwoWay, Path=IsElevated, Source={StaticResource eventViewModel}}"
Visibility="{Binding Mode=TwoWay, Path=IsAdmin, Source={StaticResource eventViewModel}, Converter={StaticResource VisibleIfTrueConverter}}"
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/>
</StackPanel>

View File

@@ -40,6 +40,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
public static bool IsElevated { get; set; }
public static bool IsUserAnAdmin { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ShellPage"/> class.
/// Shell page constructor.
@@ -77,6 +79,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
IsElevated = isElevated;
}
public void SetIsUserAnAdmin(bool isAdmin)
{
IsUserAnAdmin = isAdmin;
}
public void Refresh()
{
shellFrame.Navigate(typeof(GeneralPage));