|
2 | 2 | using System.Reflection; |
3 | 3 |
|
4 | 4 | using Avalonia.Controls.ApplicationLifetimes; |
| 5 | +using Avalonia.Styling; |
| 6 | + |
| 7 | +using FluentAvalonia.Styling; |
5 | 8 |
|
6 | 9 | using KeyboardSwitch.Core.Exceptions; |
7 | 10 | using KeyboardSwitch.Core.Logging; |
| 11 | +using KeyboardSwitch.Settings.Themes; |
8 | 12 |
|
9 | 13 | #if WINDOWS |
10 | 14 | using KeyboardSwitch.Windows; |
@@ -76,6 +80,8 @@ private async Task<MainViewModel> InitializeApp() |
76 | 80 | var mainViewModel = new MainViewModel(appSettings); |
77 | 81 | openExternally.InvokeCommand(mainViewModel.OpenExternally); |
78 | 82 |
|
| 83 | + this.SetTheme(appSettings); |
| 84 | + |
79 | 85 | return mainViewModel; |
80 | 86 | } catch (IncompatibleAppVersionException e) |
81 | 87 | { |
@@ -193,6 +199,28 @@ private async Task<MainWindow> CreateMainWindow(MainViewModel viewModel) |
193 | 199 | return window; |
194 | 200 | } |
195 | 201 |
|
| 202 | + private void SetTheme(AppSettings appSettings) |
| 203 | + { |
| 204 | + if (appSettings.AppTheme == AppTheme.MacOS) |
| 205 | + { |
| 206 | + this.Styles.Insert(0, new MacOSTheme()); |
| 207 | + } else |
| 208 | + { |
| 209 | + this.Styles.Insert(0, new FluentAvaloniaTheme |
| 210 | + { |
| 211 | + PreferUserAccentColor = true, |
| 212 | + PreferSystemTheme = true |
| 213 | + }); |
| 214 | + } |
| 215 | + |
| 216 | + this.RequestedThemeVariant = appSettings.AppThemeVariant switch |
| 217 | + { |
| 218 | + AppThemeVariant.Light => ThemeVariant.Light, |
| 219 | + AppThemeVariant.Dark => ThemeVariant.Dark, |
| 220 | + _ => ThemeVariant.Default |
| 221 | + }; |
| 222 | + } |
| 223 | + |
196 | 224 | private void SaveAppState() |
197 | 225 | { |
198 | 226 | if (this.desktop.MainWindow == null) |
|
0 commit comments