@@ -17,8 +17,8 @@ namespace Files.App.Helpers
1717 public static class ThemeHelper
1818 {
1919 private const string selectedAppThemeKey = "theme" ;
20- private static Window currentApplicationWindow ;
21- private static AppWindowTitleBar titleBar ;
20+ private static Window ? currentApplicationWindow ;
21+ private static AppWindowTitleBar ? titleBar ;
2222
2323 // Keep reference so it does not get optimized/garbage collected
2424 public static UISettings UiSettings ;
@@ -49,7 +49,8 @@ public static void Initialize()
4949 currentApplicationWindow = App . Window ;
5050
5151 // Set TitleBar background color
52- titleBar = App . GetAppWindow ( currentApplicationWindow ) . TitleBar ;
52+ if ( currentApplicationWindow is not null )
53+ titleBar = App . GetAppWindow ( currentApplicationWindow ) . TitleBar ;
5354
5455 // Apply the desired theme based on what is set in the application settings
5556 ApplyTheme ( ) ;
@@ -62,24 +63,19 @@ public static void Initialize()
6263 private static async void UiSettings_ColorValuesChanged ( UISettings sender , object args )
6364 {
6465 // Make sure we have a reference to our window so we dispatch a UI change
65- if ( currentApplicationWindow is not null )
66- {
67- // Dispatch on UI thread so that we have a current appbar to access and change
68- await currentApplicationWindow . DispatcherQueue . EnqueueAsync ( ( ) =>
69- {
70- ApplyTheme ( ) ;
71- } ) ;
72- }
66+ if ( currentApplicationWindow is null )
67+ return ;
68+
69+ // Dispatch on UI thread so that we have a current appbar to access and change
70+ await currentApplicationWindow . DispatcherQueue . EnqueueAsync ( ApplyTheme ) ;
7371 }
7472
7573 private static void ApplyTheme ( )
7674 {
7775 var rootTheme = RootTheme ;
7876
7977 if ( App . Window . Content is FrameworkElement rootElement )
80- {
8178 rootElement . RequestedTheme = rootTheme ;
82- }
8379
8480 if ( titleBar is not null )
8581 {
0 commit comments