Skip to content

Commit

Permalink
Merge pull request #999 from cbordeman/Add-default-theme-setting
Browse files Browse the repository at this point in the history
Implemented "System" option for theme.
  • Loading branch information
rmcrackan authored Oct 14, 2024
2 parents f7a4a95 + 63e28b1 commit 4f5df44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
20 changes: 11 additions & 9 deletions Source/LibationAvalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ private async void Setup_Closing(object sender, System.ComponentModel.CancelEven

if (setupDialog.Config.LibationSettingsAreValid)
{
var theme
= setupDialog.SelectedTheme.Content is nameof(ThemeVariant.Dark)
? nameof(ThemeVariant.Dark)
: nameof(ThemeVariant.Light);

string theme = setupDialog.SelectedTheme.Content as string;

setupDialog.Config.SetString(theme, nameof(ThemeVariant));


await RunMigrationsAsync(setupDialog.Config);
LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
AudibleUtilities.AudibleApiStorage.EnsureAccountsSettingsFileExists();
Expand Down Expand Up @@ -208,9 +204,15 @@ static async Task CancelInstallation()

private static void ShowMainWindow(IClassicDesktopStyleApplicationLifetime desktop)
{
Current.RequestedThemeVariant = Configuration.Instance.GetString(propertyName: nameof(ThemeVariant)) is "Dark" ? ThemeVariant.Dark : ThemeVariant.Light;

//Reload colors for current theme
Current.RequestedThemeVariant = Configuration.Instance.GetString(propertyName: nameof(ThemeVariant)) switch
{
nameof(ThemeVariant.Dark) => ThemeVariant.Dark,
nameof(ThemeVariant.Light) => ThemeVariant.Light,
// "System"
_ => ThemeVariant.Default
};

//Reload colors for current theme
LoadStyles();
var mainWindow = new MainWindow();
desktop.MainWindow = MainWindow = mainWindow;
Expand Down
5 changes: 4 additions & 1 deletion Source/LibationAvalonia/Dialogs/SetupDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dialogs="clr-namespace:LibationAvalonia.Dialogs"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="350"
x:Class="LibationAvalonia.Dialogs.SetupDialog"
WindowStartupLocation="CenterScreen"
Width="500" Height="350"
Icon="/Assets/libation.ico"
Title="Welcome to Libation">
Title="Welcome to Libation"
x:DataType="dialogs:SetupDialog">

<Grid
Margin="10"
Expand Down Expand Up @@ -58,6 +60,7 @@
SelectedIndex="0"
SelectedItem="{Binding SelectedTheme, Mode=OneWayToSource}">
<ComboBox.Items>
<ComboBoxItem Content="System" />
<ComboBoxItem Content="Light" />
<ComboBoxItem Content="Dark" />
</ComboBox.Items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public void LoadSettings(Configuration config)
LoggingLevel = config.LogLevel;
GridScaleFactor = scaleFactorToLinearRange(config.GridScaleFactor);
GridFontScaleFactor = scaleFactorToLinearRange(config.GridFontScaleFactor);
ThemeVariant = initialThemeVariant
= Configuration.Instance.GetString(propertyName: nameof(ThemeVariant)) is nameof(Avalonia.Styling.ThemeVariant.Dark)
? nameof(Avalonia.Styling.ThemeVariant.Dark)
: nameof(Avalonia.Styling.ThemeVariant.Light);

ThemeVariant = initialThemeVariant = Configuration.Instance.GetString(propertyName: nameof(ThemeVariant));
if (string.IsNullOrWhiteSpace(initialThemeVariant))
ThemeVariant = initialThemeVariant = "System";
}

public void SaveSettings(Configuration config)
Expand Down Expand Up @@ -83,7 +83,7 @@ public void ApplyDisplaySettings()
public string GridScaleFactorText { get; } = Configuration.GetDescription(nameof(Configuration.GridScaleFactor));
public string GridFontScaleFactorText { get; } = Configuration.GetDescription(nameof(Configuration.GridFontScaleFactor));
public string BetaOptInText { get; } = Configuration.GetDescription(nameof(Configuration.BetaOptIn));
public string[] Themes { get; } = { nameof(Avalonia.Styling.ThemeVariant.Light), nameof(Avalonia.Styling.ThemeVariant.Dark) };
public string[] Themes { get; } = { "System", nameof(Avalonia.Styling.ThemeVariant.Light), nameof(Avalonia.Styling.ThemeVariant.Dark) };

public string BooksDirectory { get; set; }
public bool SavePodcastsToParentFolder { get; set; }
Expand Down

0 comments on commit 4f5df44

Please sign in to comment.