Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Optimize>true</Optimize>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using UniGetUI.Interface.Telemetry;
using UniGetUI.PackageEngine.Interfaces;
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
using UniGetUI.Pages.SettingsPages;

namespace UniGetUI
{
Expand Down Expand Up @@ -52,7 +53,6 @@

public bool RaiseExceptionAsFatal = true;

public SettingsPage settings = null!;
public MainWindow MainWindow = null!;
public ThemeListener ThemeListener = null!;

Expand Down Expand Up @@ -379,7 +379,7 @@
MainWindow.DispatcherQueue.TryEnqueue(MainWindow.Activate);
}

public async void DisposeAndQuit(int outputCode = 0)

Check warning on line 382 in src/UniGetUI/App.xaml.cs

View workflow job for this annotation

GitHub Actions / test-codebase

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Logger.Warn("Quitting UniGetUI");
DWMThreadHelper.ChangeState_DWM(false);
Expand Down
7 changes: 2 additions & 5 deletions src/UniGetUI/Controls/Announcer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
mc:Ignorable="d">

<Grid TabIndex="99">
<Grid x:Name="g">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
<Grid x:Name="g" ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<RichTextBlock x:Name="_textblock" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"/>
<Image x:Name="_image" Grid.Column="1" Grid.Row="0" Width="80" Height="80"></Image>
<Image x:Name="_image" Grid.Column="1" Grid.Row="0" Width="80"/>
</Grid>
</Grid>
</UserControl>
2 changes: 1 addition & 1 deletion src/UniGetUI/Controls/Announcer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void SetText(string title, string body, string linkId, string linkName)
link.Inlines.Add(new Run { Text = linkName });
link.NavigateUri = new Uri("https://marticliment.com/redirect?" + linkId);
paragraph.Inlines[^1] = link;
paragraph.Inlines.Add(new LineBreak());
paragraph.Inlines.Add(new Run() { Text= "" });

_textblock.Blocks.Add(paragraph);
}
Expand Down
1 change: 0 additions & 1 deletion src/UniGetUI/Controls/SettingsWidgets/ButtonCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public ButtonCard()
{
_button.MinWidth = 200;
_button.Click += (_, _) => { Click?.Invoke(this, EventArgs.Empty); };
DefaultStyleKey = typeof(ButtonCard);
Content = _button;
}
}
Expand Down
56 changes: 37 additions & 19 deletions src/UniGetUI/Controls/SettingsWidgets/CheckboxButtonCard.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using CommunityToolkit.WinUI.Controls;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using Windows.UI.Text;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -11,7 +13,8 @@ namespace UniGetUI.Interface.Widgets
{
public sealed class CheckboxButtonCard : SettingsCard
{
public CheckBox CheckBox;
public ToggleSwitch _checkbox;
public TextBlock _textblock;
public Button Button;
private bool IS_INVERTED;

Expand All @@ -21,23 +24,24 @@ public string SettingName
set {
setting_name = value;
IS_INVERTED = value.StartsWith("Disable");
CheckBox.IsChecked = Settings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
Button.IsEnabled = (CheckBox.IsChecked ?? false) || _buttonAlwaysOn ;
_checkbox.IsOn = Settings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
Button.IsEnabled = (_checkbox.IsOn) || _buttonAlwaysOn ;
}
}

public bool ForceInversion { get; set; }

public bool Checked
{
get => CheckBox.IsChecked ?? false;
get => _checkbox.IsOn;
}
public event EventHandler<EventArgs>? StateChanged;
public new event EventHandler<RoutedEventArgs>? Click;

public string CheckboxText
{
set => CheckBox.Content = CoreTools.Translate(value);
set => _textblock.Text = CoreTools.Translate(value);
}

public string ButtonText
Expand All @@ -51,36 +55,50 @@ public bool ButtonAlwaysOn
set
{
_buttonAlwaysOn = value;
Button.IsEnabled = (CheckBox.IsChecked ?? false) || _buttonAlwaysOn ;
Button.IsEnabled = (_checkbox.IsOn) || _buttonAlwaysOn ;
}
}

public CheckboxButtonCard()
{
Button = new Button();
CheckBox = new CheckBox();
_checkbox = new ToggleSwitch()
{
Margin = new Thickness(-8, 0, 0, 0)
};
_textblock = new TextBlock()
{
VerticalAlignment = VerticalAlignment.Center,
Margin = new(12, 0, 8, 0),
TextWrapping = TextWrapping.Wrap,
Style = (Style)Application.Current.Resources["BaseTextBlockStyle"],
FontWeight = new FontWeight(450),
Foreground = (SolidColorBrush)Application.Current.Resources["ButtonForeground"]
};
IS_INVERTED = false;
_checkbox.OnContent = _checkbox.OffContent = "";

//ContentAlignment = ContentAlignment.Left;
//HorizontalAlignment = HorizontalAlignment.Stretch;

DefaultStyleKey = typeof(CheckboxCard);
Description = CheckBox;
Grid g = new Grid();
g.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
g.Children.Add(_checkbox);
g.Children.Add(_textblock);
Grid.SetColumn(_textblock, 1);

Description = g;
Content = Button;
CheckBox.HorizontalAlignment = HorizontalAlignment.Stretch;
CheckBox.Checked += (_, _) =>
g.HorizontalAlignment = HorizontalAlignment.Stretch;
_checkbox.Toggled += (_, _) =>
{
Settings.Set(setting_name, true ^ IS_INVERTED ^ ForceInversion);
Settings.Set(setting_name, _checkbox.IsOn ^ IS_INVERTED ^ ForceInversion);
StateChanged?.Invoke(this, EventArgs.Empty);
Button.IsEnabled = true;
Button.IsEnabled = _checkbox.IsOn ? true : _buttonAlwaysOn;
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
};

CheckBox.Unchecked += (_, _) =>
{
Settings.Set(setting_name, false ^ IS_INVERTED ^ ForceInversion);
StateChanged?.Invoke(this, EventArgs.Empty);
Button.IsEnabled = _buttonAlwaysOn;
};

Button.MinWidth = 200;
Button.Click += (s, e) => Click?.Invoke(s, e);
Expand Down
99 changes: 84 additions & 15 deletions src/UniGetUI/Controls/SettingsWidgets/CheckboxCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,116 @@

namespace UniGetUI.Interface.Widgets
{
public sealed partial class CheckboxCard : SettingsCard
public partial class CheckboxCard : SettingsCard
{
public CheckBox _checkbox;
private bool IS_INVERTED;
public ToggleSwitch _checkbox;
public TextBlock _textblock;
protected bool IS_INVERTED;

private string setting_name = "";
public string SettingName
protected string setting_name = "";
public virtual string SettingName
{
set {
set
{
setting_name = value;
IS_INVERTED = value.StartsWith("Disable");
_checkbox.IsChecked = Settings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
_checkbox.IsOn = Settings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
}
}

public bool ForceInversion { get; set; }

public bool Checked
{
get => _checkbox.IsChecked ?? false;
get => _checkbox.IsOn;
}
public event EventHandler<EventArgs>? StateChanged;
public virtual event EventHandler<EventArgs>? StateChanged;

public string Text
{
set => _checkbox.Content = CoreTools.Translate(value);
set => _textblock.Text = CoreTools.Translate(value);
}

public CheckboxCard()
{
_checkbox = new CheckBox();
_checkbox = new ToggleSwitch()
{
Margin = new Thickness(-8, 0, 0, 0)
};
_textblock = new TextBlock()
{
VerticalAlignment = VerticalAlignment.Center,
Margin = new(12, 0, 8, 0),
TextWrapping = TextWrapping.Wrap
};

_checkbox.OnContent = _checkbox.OffContent = "";
IS_INVERTED = false;

ContentAlignment = ContentAlignment.Left;
HorizontalAlignment = HorizontalAlignment.Stretch;

DefaultStyleKey = typeof(CheckboxCard);
Content = _checkbox;
Grid g = new Grid();
g.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
g.Children.Add(_checkbox);
g.Children.Add(_textblock);
Grid.SetColumn(_textblock, 1);
Content = g;

_checkbox.HorizontalAlignment = HorizontalAlignment.Stretch;
_checkbox.Checked += (_, _) => { Settings.Set(setting_name, true ^ IS_INVERTED ^ ForceInversion); StateChanged?.Invoke(this, EventArgs.Empty); };
_checkbox.Unchecked += (_, _) => { Settings.Set(setting_name, false ^ IS_INVERTED ^ ForceInversion); StateChanged?.Invoke(this, EventArgs.Empty); };
_checkbox.Toggled += _checkbox_Toggled;
}
protected virtual void _checkbox_Toggled(object sender, RoutedEventArgs e)
{
Settings.Set(setting_name, _checkbox.IsOn ^ IS_INVERTED ^ ForceInversion);
StateChanged?.Invoke(this, EventArgs.Empty);
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
}
}

public partial class CheckboxCard_Dict : CheckboxCard
{
public override event EventHandler<EventArgs>? StateChanged;

private string _dictName = "";
public string DictionaryName
{
set
{
_dictName = value;
IS_INVERTED = value.StartsWith("Disable");
if (setting_name != "")
{
_checkbox.IsOn = Settings.GetDictionaryItem<string, bool>(_dictName, setting_name) ^ IS_INVERTED ^ ForceInversion;
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
}
}
}

public override string SettingName
{
set
{
setting_name = value;
if (_dictName != "")
{
_checkbox.IsOn = Settings.GetDictionaryItem<string, bool>(_dictName, setting_name) ^ IS_INVERTED ^ ForceInversion;
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
}
}
}

public CheckboxCard_Dict() : base()
{
}

protected override void _checkbox_Toggled(object sender, RoutedEventArgs e)
{
Settings.SetDictionaryItem(_dictName, setting_name, _checkbox.IsOn ^ IS_INVERTED ^ ForceInversion);
StateChanged?.Invoke(this, EventArgs.Empty);
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
}
}
}
1 change: 0 additions & 1 deletion src/UniGetUI/Controls/SettingsWidgets/ComboboxCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public ComboboxCard()
{
_combobox.MinWidth = 200;
_combobox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = _elements });
DefaultStyleKey = typeof(CheckboxCard);
Content = _combobox;
}

Expand Down
65 changes: 0 additions & 65 deletions src/UniGetUI/Controls/SettingsWidgets/SettingsEntry.cs

This file was deleted.

Loading
Loading