mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
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:
committed by
GitHub
parent
3dc61962de
commit
a13c8cb71e
@@ -41,6 +41,7 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
|||||||
});
|
});
|
||||||
|
|
||||||
shellPage.SetElevationStatus(Program.IsElevated);
|
shellPage.SetElevationStatus(Program.IsElevated);
|
||||||
|
shellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin);
|
||||||
shellPage.Refresh();
|
shellPage.Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,16 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
|||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
// Quantity of arguments
|
||||||
|
private const int ArgumentsQty = 5;
|
||||||
|
|
||||||
// Create an instance of the IPC wrapper.
|
// Create an instance of the IPC wrapper.
|
||||||
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
||||||
|
|
||||||
public static bool IsElevated { get; set; }
|
public static bool IsElevated { get; set; }
|
||||||
|
|
||||||
|
public static bool IsUserAnAdmin { get; set; }
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -24,7 +29,7 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
|||||||
App app = new App();
|
App app = new App();
|
||||||
app.InitializeComponent();
|
app.InitializeComponent();
|
||||||
|
|
||||||
if (args.Length > 3)
|
if (args.Length >= ArgumentsQty)
|
||||||
{
|
{
|
||||||
if (args[4] == "true")
|
if (args[4] == "true")
|
||||||
{
|
{
|
||||||
@@ -35,6 +40,15 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
|||||||
IsElevated = false;
|
IsElevated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args[5] == "true")
|
||||||
|
{
|
||||||
|
IsUserAnAdmin = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsUserAnAdmin = false;
|
||||||
|
}
|
||||||
|
|
||||||
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
|
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
|
||||||
ipcmanager.Start();
|
ipcmanager.Start();
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ using System.Runtime.CompilerServices;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
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.ViewModels.Commands;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Windows.ApplicationModel.Resources;
|
using Windows.ApplicationModel.Resources;
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
|
||||||
using Windows.Data.Html;
|
using Windows.Data.Html;
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
using Windows.UI.Popups;
|
using Windows.UI.Popups;
|
||||||
@@ -97,12 +97,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
_autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
|
_autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
|
||||||
_isElevated = ShellPage.IsElevated;
|
_isElevated = ShellPage.IsElevated;
|
||||||
_runElevated = GeneralSettingsConfigs.RunElevated;
|
_runElevated = GeneralSettingsConfigs.RunElevated;
|
||||||
|
_isAdmin = ShellPage.IsUserAnAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _packaged = false;
|
private bool _packaged = false;
|
||||||
private bool _startup = false;
|
private bool _startup = false;
|
||||||
private bool _isElevated = false;
|
private bool _isElevated = false;
|
||||||
private bool _runElevated = false;
|
private bool _runElevated = false;
|
||||||
|
private bool _isAdmin = false;
|
||||||
private bool _isDarkThemeRadioButtonChecked = false;
|
private bool _isDarkThemeRadioButtonChecked = false;
|
||||||
private bool _isLightThemeRadioButtonChecked = false;
|
private bool _isLightThemeRadioButtonChecked = false;
|
||||||
private bool _isSystemThemeRadioButtonChecked = 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
|
public bool AutoDownloadUpdates
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible"/>
|
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible"/>
|
||||||
|
<converters:BoolToVisibilityConverter x:Key="VisibleIfTrueConverter"/>
|
||||||
<viewModel:GeneralViewModel x:Key="eventViewModel"/>
|
<viewModel:GeneralViewModel x:Key="eventViewModel"/>
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
@@ -119,14 +120,9 @@
|
|||||||
Command="{Binding CheckFoUpdatesEventHandler, Source={StaticResource eventViewModel}}"
|
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"
|
<ToggleSwitch x:Uid="GeneralPage_ToggleSwitch_AutoDownloadUpdates"
|
||||||
Margin="{StaticResource MediumTopMargin}"
|
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}}"/>
|
IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates, Source={StaticResource eventViewModel}}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
|
|
||||||
public static bool IsElevated { get; set; }
|
public static bool IsElevated { get; set; }
|
||||||
|
|
||||||
|
public static bool IsUserAnAdmin { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ShellPage"/> class.
|
/// Initializes a new instance of the <see cref="ShellPage"/> class.
|
||||||
/// Shell page constructor.
|
/// Shell page constructor.
|
||||||
@@ -77,6 +79,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
IsElevated = isElevated;
|
IsElevated = isElevated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetIsUserAnAdmin(bool isAdmin)
|
||||||
|
{
|
||||||
|
IsUserAnAdmin = isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
shellFrame.Navigate(typeof(GeneralPage));
|
shellFrame.Navigate(typeof(GeneralPage));
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ json::JsonObject load_general_settings()
|
|||||||
settings_theme = L"system";
|
settings_theme = L"system";
|
||||||
}
|
}
|
||||||
run_as_elevated = loaded.GetNamedBoolean(L"run_elevated", false);
|
run_as_elevated = loaded.GetNamedBoolean(L"run_elevated", false);
|
||||||
download_updates_automatically = loaded.GetNamedBoolean(L"download_updates_automatically", true);
|
download_updates_automatically = loaded.GetNamedBoolean(L"download_updates_automatically", true) && check_user_is_admin();
|
||||||
|
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,6 +276,18 @@ void run_settings_window()
|
|||||||
settings_elevatedStatus = L"false";
|
settings_elevatedStatus = L"false";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isAdmin{ get_general_settings().isAdmin };
|
||||||
|
std::wstring settings_isUserAnAdmin;
|
||||||
|
|
||||||
|
if (isAdmin)
|
||||||
|
{
|
||||||
|
settings_isUserAnAdmin = L"true";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings_isUserAnAdmin = L"false";
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring executable_args = L"\"";
|
std::wstring executable_args = L"\"";
|
||||||
executable_args.append(executable_path);
|
executable_args.append(executable_path);
|
||||||
executable_args.append(L"\" ");
|
executable_args.append(L"\" ");
|
||||||
@@ -288,6 +300,8 @@ void run_settings_window()
|
|||||||
executable_args.append(settings_theme);
|
executable_args.append(settings_theme);
|
||||||
executable_args.append(L" ");
|
executable_args.append(L" ");
|
||||||
executable_args.append(settings_elevatedStatus);
|
executable_args.append(settings_elevatedStatus);
|
||||||
|
executable_args.append(L" ");
|
||||||
|
executable_args.append(settings_isUserAnAdmin);
|
||||||
|
|
||||||
BOOL process_created = false;
|
BOOL process_created = false;
|
||||||
if (is_process_elevated())
|
if (is_process_elevated())
|
||||||
|
|||||||
Reference in New Issue
Block a user