Skip to content

Commit 550c1ce

Browse files
committed
Add new "Dangerous settings" settings section, add more things to SecureSettingsCheckbox
1 parent 64767d4 commit 550c1ce

6 files changed

Lines changed: 80 additions & 21 deletions

File tree

src/UniGetUI/Controls/SettingsWidgets/SecureCheckboxCard.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.WinUI.Controls;
22
using Microsoft.UI.Xaml;
33
using Microsoft.UI.Xaml.Controls;
4+
using Microsoft.UI.Xaml.Media;
45
using UniGetUI.Core.Logging;
56
using UniGetUI.Core.SettingsEngine.SecureSettings;
67
using UniGetUI.Core.Tools;
@@ -14,6 +15,7 @@ public partial class SecureCheckboxCard : SettingsCard
1415
{
1516
public ToggleSwitch _checkbox;
1617
public TextBlock _textblock;
18+
public TextBlock _warningBlock;
1719
public ProgressRing _loading;
1820
protected bool IS_INVERTED;
1921

@@ -44,6 +46,15 @@ public string Text
4446
set => _textblock.Text = CoreTools.Translate(value);
4547
}
4648

49+
public string WarningText
50+
{
51+
set
52+
{
53+
_warningBlock.Text = CoreTools.Translate(value);
54+
_warningBlock.Visibility = value.Any() ? Visibility.Visible : Visibility.Collapsed;
55+
}
56+
}
57+
4758
public SecureCheckboxCard()
4859
{
4960
_checkbox = new ToggleSwitch()
@@ -58,14 +69,29 @@ public SecureCheckboxCard()
5869
Margin = new Thickness(0, 0, 0, 0),
5970
TextWrapping = TextWrapping.Wrap
6071
};
72+
_warningBlock = new TextBlock()
73+
{
74+
VerticalAlignment = VerticalAlignment.Center,
75+
Margin = new Thickness(0, 0, 0, 0),
76+
TextWrapping = TextWrapping.Wrap,
77+
Foreground = (SolidColorBrush)Application.Current.Resources["SystemControlErrorTextForegroundBrush"],
78+
FontSize = 12,
79+
Visibility = Visibility.Collapsed,
80+
};
6181
IS_INVERTED = false;
6282
Content = new StackPanel()
6383
{
6484
Spacing = 4,
6585
Orientation = Orientation.Horizontal,
6686
Children = { _loading, _checkbox },
6787
};
68-
Header = _textblock;
88+
//Header = _textblock;
89+
Header = new StackPanel()
90+
{
91+
Spacing = 4,
92+
Orientation = Orientation.Vertical,
93+
Children = { _textblock, _warningBlock }
94+
};
6995

7096
_checkbox.HorizontalAlignment = HorizontalAlignment.Stretch;
7197
_checkbox.Toggled += (s, e) => _ = _checkbox_Toggled();
@@ -82,14 +108,14 @@ protected virtual async Task _checkbox_Toggled()
82108
StateChanged?.Invoke(this, EventArgs.Empty);
83109
await SecureSettings.TrySet(setting_name, _checkbox.IsOn ^ IS_INVERTED ^ ForceInversion);
84110
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
85-
_checkbox.IsOn = SecureSettings.Get(setting_name);
111+
_checkbox.IsOn = SecureSettings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
86112
_loading.Visibility = Visibility.Collapsed;
87113
_checkbox.IsEnabled = true;
88114
}
89115
catch (Exception ex)
90116
{
91117
Logger.Warn(ex);
92-
_checkbox.IsOn = SecureSettings.Get(setting_name);
118+
_checkbox.IsOn = SecureSettings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
93119
_loading.Visibility = Visibility.Collapsed;
94120
_checkbox.IsEnabled = true;
95121
}

src/UniGetUI/Pages/SettingsPages/GeneralPages/Administrator.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
VerticalContentAlignment="Center">
2626
<StackPanel>
2727

28+
<InfoBar
29+
x:Name="WarningTitlebar"
30+
CornerRadius="8"
31+
IsClosable="False"
32+
IsOpen="True"
33+
Severity="Warning" />
34+
2835
<widgets:TranslatedTextBlock
2936
Margin="4,32,4,8"
3037
FontWeight="SemiBold"

src/UniGetUI/Pages/SettingsPages/GeneralPages/Administrator.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public Administrator()
2020
DoCacheAdminRights.IsEnabled = true;
2121
DoCacheAdminRightsForBatches.IsEnabled = true;
2222
}
23+
24+
WarningTitlebar.Title = CoreTools.Translate("Warning") + "!";
25+
WarningTitlebar.Message =
26+
CoreTools.Translate("The following settings may pose a security risk, hence they are disabled by default.") + " " +
27+
CoreTools.Translate("Enable the settings below only if you fully understand what they do, and the implications they may have.") + "\n\n" +
28+
CoreTools.Translate("The settings will list, in their descriptions, the potential security issues they may have.") + " ";
29+
30+
// The following settings may pose a security risk, hence they are disabled by default. Enable them ONLY if you undertsand what you are doing. Some of those settings will show a UAC prompt before being enabled."
31+
2332
}
2433

2534
public bool CanGoBack => true;

src/UniGetUI/Pages/SettingsPages/GeneralPages/SettingsHomepage.xaml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@
5757
UnderText="Show notifications on different events" />
5858

5959
<UserControl Height="16" />
60-
6160
<widgets:SettingsPageButton
62-
x:Name="BackupOptionsExpander"
63-
Click="Backup"
61+
x:Name="AdminSettingsExpander"
62+
Click="Administrator"
6463
CornerRadius="8"
65-
Icon="disk"
66-
Text="Package backup"
67-
UnderText="Automatically save a list of all your installed packages to easily restore them." />
64+
Icon="uac"
65+
Text="Administrator rights and other dangerous settings"
66+
UnderText="Reduce UAC prompts, elevate installations by default, unlock certain dangerous features, etc." />
6867

6968
<UserControl Height="16" />
7069

@@ -88,32 +87,46 @@
8887
<UserControl Height="16" />
8988

9089
<widgets:SettingsPageButton
91-
x:Name="AdminSettingsExpander"
92-
Click="Administrator"
90+
x:Name="BackupOptionsExpander"
91+
Click="Backup"
9392
CornerRadius="8"
94-
Icon="uac"
95-
Text="Administrator privileges preferences"
96-
UnderText="Ask once or always for administrator rights, elevate installations by default" />
93+
Icon="disk"
94+
Text="Package backup"
95+
UnderText="Automatically save a list of all your installed packages to easily restore them." />
96+
9797
<UserControl Height="16" />
9898

9999
<widgets:SettingsPageButton
100-
x:Name="InternetSettings"
101-
Click="Internet"
100+
x:Name="ManagersSettingsShortcut"
101+
Click="ManagersShortcut"
102102
CornerRadius="8"
103103
Icon="Search"
104-
Text="Internet connection settings"
105-
UnderText="Proxy settings, etc." >
104+
Text="Package manager preferences"
105+
UnderText="Enable and disable package managers, change default install options, etc.">
106106
<widgets:SettingsPageButton.HeaderIcon>
107-
<FontIcon Glyph="&#xE839;" FontSize="12"/>
107+
<FontIcon FontSize="12" Glyph="&#xE835;" />
108108
</widgets:SettingsPageButton.HeaderIcon>
109109
</widgets:SettingsPageButton>
110110

111111
<UserControl Height="16" />
112112

113+
<widgets:SettingsPageButton
114+
x:Name="InternetSettings"
115+
Click="Internet"
116+
CornerRadius="8,8,0,0"
117+
Icon="Search"
118+
Text="Internet connection settings"
119+
UnderText="Proxy settings, etc.">
120+
<widgets:SettingsPageButton.HeaderIcon>
121+
<FontIcon FontSize="12" Glyph="&#xE839;" />
122+
</widgets:SettingsPageButton.HeaderIcon>
123+
</widgets:SettingsPageButton>
124+
113125
<widgets:SettingsPageButton
114126
x:Name="ExperimentalSettingsExpander"
127+
BorderThickness="1,0,1,1"
115128
Click="Experimental"
116-
CornerRadius="8"
129+
CornerRadius="0,0,8,8"
117130
Icon="experimental"
118131
Text="Experimental settings and developer options"
119132
UnderText="Beta features and other options that shouldn't be touched" />

src/UniGetUI/Pages/SettingsPages/GeneralPages/SettingsHomepage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public SettingsHomepage()
3333
public void Operations(object s, RoutedEventArgs e) => NavigationRequested?.Invoke(this, typeof(Operations));
3434
public void Startup(object s, RoutedEventArgs e) => NavigationRequested?.Invoke(this, typeof(Updates));
3535
private void Internet(object sender, RoutedEventArgs e) => NavigationRequested?.Invoke(this, typeof(Internet));
36-
36+
private void ManagersShortcut(object sender, RoutedEventArgs e) => NavigationRequested?.Invoke(this, typeof(ManagersHomepage));
3737
}
3838
}

src/UniGetUI/Pages/SettingsPages/SettingsBasePage.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ private void Page_RestartRequired(object? sender, EventArgs e)
8282

8383
private void Page_NavigationRequested(object? sender, Type e)
8484
{
85+
if(e == typeof(ManagersHomepage))
86+
{
87+
MainApp.Instance.MainWindow.NavigationPage.NavigateTo(Interface.PageType.Managers);
88+
}
8589
if(e.IsSubclassOf(typeof(PackageManager)))
8690
{
8791
MainNavigationFrame.Navigate(typeof(PackageManagerPage), e, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight} );

0 commit comments

Comments
 (0)