mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Only allow to edit System vars if running elevated
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
|
||||
xmlns:converters="using:EnvironmentVariables.Converters"
|
||||
xmlns:converters1="using:CommunityToolkit.WinUI.UI.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||
@@ -20,7 +21,7 @@
|
||||
Click="EditVariable_Click"
|
||||
CommandParameter="{x:Bind (models:Variable)}"
|
||||
Header="{x:Bind Name, Mode=TwoWay}"
|
||||
IsClickEnabled="True">
|
||||
IsClickEnabled="{x:Bind Editable, Mode=OneWay}">
|
||||
<TextBlock
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
IsTextSelectionEnabled="True"
|
||||
@@ -29,6 +30,11 @@
|
||||
</DataTemplate>
|
||||
|
||||
<converters:VariableTypeToGlyphConverter x:Key="VariableTypeToGlyphConverter" />
|
||||
<converters1:BoolToVisibilityConverter
|
||||
x:Key="BoolToInvertedVisibilityConverter"
|
||||
FalseValue="Visible"
|
||||
TrueValue="Collapsed" />
|
||||
<converters1:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
</Page.Resources>
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="Loaded">
|
||||
@@ -110,6 +116,12 @@
|
||||
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||
ItemTemplate="{StaticResource VariableTemplate}"
|
||||
ItemsSource="{x:Bind ViewModel.UserDefaultSet.Variables, Mode=OneWay}" />
|
||||
<InfoBar
|
||||
x:Uid="EditSystemDefaultSetInfoBar"
|
||||
Margin="0,8,0,0"
|
||||
IsOpen="{x:Bind ViewModel.IsElevated, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
|
||||
Severity="Informational"
|
||||
Visibility="{x:Bind ViewModel.IsElevated, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}" />
|
||||
<labs:SettingsExpander
|
||||
Margin="0,0,0,4"
|
||||
Header="{x:Bind ViewModel.SystemDefaultSet.Name}"
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace EnvironmentVariables.Models
|
||||
[ObservableProperty]
|
||||
private string _values;
|
||||
|
||||
public bool Editable { get; private set; }
|
||||
|
||||
public VariablesSetType ParentType { get; set; }
|
||||
|
||||
public List<string> ValuesList { get; set; }
|
||||
@@ -30,6 +32,7 @@ namespace EnvironmentVariables.Models
|
||||
Name = name;
|
||||
Values = values;
|
||||
ParentType = parentType;
|
||||
Editable = ParentType == VariablesSetType.User || (ParentType == VariablesSetType.System && App.GetService<IElevationHelper>().IsElevated);
|
||||
|
||||
var splitValues = Values.Split(';');
|
||||
if (splitValues.Length > 0)
|
||||
|
||||
@@ -203,4 +203,7 @@
|
||||
<data name="NewProfileVariablesListViewHeader.Text" xml:space="preserve">
|
||||
<value>Variables</value>
|
||||
</data>
|
||||
<data name="EditSystemDefaultSetInfoBar.Title" xml:space="preserve">
|
||||
<value>You need to run as administrator to edit System environment variables</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -32,11 +32,16 @@ namespace EnvironmentVariables.ViewModels
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Variable> _appliedVariables = new ObservableCollection<Variable>();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isElevated;
|
||||
|
||||
public ProfileVariablesSet AppliedProfile { get; set; }
|
||||
|
||||
public MainViewModel(IEnvironmentVariablesService environmentVariablesService)
|
||||
{
|
||||
_environmentVariablesService = environmentVariablesService;
|
||||
var isElevated = App.GetService<IElevationHelper>().IsElevated;
|
||||
IsElevated = isElevated;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
Reference in New Issue
Block a user