store theme in UiConfig
MODIFY
WalletWasabi.Fluent.Desktop/Program.cs
WalletWasabi.Fluent.Desktop/Program.cs
@@ -8,6 +8,7 @@ using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels;
using WalletWasabi.Gui;
using WalletWasabi.Gui.CommandLine;
@@ -60,7 +61,11 @@ namespace WalletWasabi.Fluent.Desktop
Logger.LogSoftwareStarted("Wasabi GUI");
BuildAvaloniaApp()
- .AfterSetup(_ => AppMainAsync(args))
+ .AfterSetup(_ =>
+ {
+ ThemeHelper.ApplyTheme(Global!.UiConfig.DarkModeEnabled);
+ AppMainAsync(args);
+ })
.StartWithClassicDesktopLifetime(args);
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
-using Avalonia;
-using Avalonia.Markup.Xaml.Styling;
using NBitcoin;
using ReactiveUI;
+using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Gui;
using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.Validation;
@@ -26,7 +25,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
{
this.ValidateProperty(x => x.DustThreshold, ValidateDustThreshold);
- _darkModeEnabled = true; // TODO: Get from config file.
+ _darkModeEnabled = global.UiConfig.DarkModeEnabled;
_autocopy = global.UiConfig.Autocopy;
_customFee = global.UiConfig.IsCustomFee;
_customChangeAddress = global.UiConfig.IsCustomChangeAddress;
@@ -42,21 +41,10 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
this.WhenAnyValue(x => x.DarkModeEnabled)
.Skip(1)
.Subscribe(
- _ =>
+ x =>
{
- var currentTheme = Application.Current.Styles.Select(x => (StyleInclude)x).FirstOrDefault(x => x.Source is { } && x.Source.AbsolutePath.Contains("Themes"));
-
- if (currentTheme?.Source is { } src)
- {
- var themeIndex = Application.Current.Styles.IndexOf(currentTheme);
-
- var newTheme = new StyleInclude(new Uri("avares://WalletWasabi.Fluent/App.xaml"))
- {
- Source = new Uri($"avares://WalletWasabi.Fluent/Styles/Themes/{(src.AbsolutePath.Contains("Light") ? "BaseDark" : "BaseLight")}.xaml")
- };
-
- Application.Current.Styles[themeIndex] = newTheme;
- }
+ global.UiConfig.DarkModeEnabled = x;
+ ThemeHelper.ApplyTheme(x);
});
this.WhenAnyValue(x => x.Autocopy)

MODIFY
WalletWasabi.Gui/UiConfig.cs
WalletWasabi.Gui/UiConfig.cs
@@ -20,6 +20,7 @@ namespace WalletWasabi.Gui
private bool _isCustomChangeAddress;
private bool _autocopy;
private int _feeDisplayFormat;
+ private bool _darkModeEnabled;
public UiConfig() : base()
{
@@ -31,7 +32,8 @@ namespace WalletWasabi.Gui
x => x.LockScreenPinHash,
x => x.Autocopy,
x => x.IsCustomFee,
- x => x.IsCustomChangeAddress)
+ x => x.IsCustomChangeAddress,
+ x => x.DarkModeEnabled)
.Throttle(TimeSpan.FromSeconds(1))
.Skip(1) // Won't save on UiConfig creation.
.ObserveOn(RxApp.TaskpoolScheduler)
@@ -106,6 +108,14 @@ namespace WalletWasabi.Gui
set => RaiseAndSetIfChanged(ref _lockScreenPinHash, value);
}
+ [DefaultValue(true)]
+ [JsonProperty(PropertyName = "DarkModeEnabled", DefaultValueHandling = DefaultValueHandling.Populate)]
+ public bool DarkModeEnabled
+ {
+ get => _darkModeEnabled;
+ set => RaiseAndSetIfChanged(ref _darkModeEnabled, value);
+ }
+
[JsonProperty(PropertyName = "CoinListViewSortingPreference")]
[JsonConverter(typeof(SortingPreferenceJsonConverter))]
public SortingPreference CoinListViewSortingPreference { get; internal set; } = new SortingPreference(SortOrder.Increasing, "Amount");

store theme in UiConfig