@@ -17,8 +17,8 @@ namespace Files.App.Helpers
17
17
public static class ThemeHelper
18
18
{
19
19
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 ;
22
22
23
23
// Keep reference so it does not get optimized/garbage collected
24
24
public static UISettings UiSettings ;
@@ -49,7 +49,8 @@ public static void Initialize()
49
49
currentApplicationWindow = App . Window ;
50
50
51
51
// Set TitleBar background color
52
- titleBar = App . GetAppWindow ( currentApplicationWindow ) . TitleBar ;
52
+ if ( currentApplicationWindow is not null )
53
+ titleBar = App . GetAppWindow ( currentApplicationWindow ) . TitleBar ;
53
54
54
55
// Apply the desired theme based on what is set in the application settings
55
56
ApplyTheme ( ) ;
@@ -62,24 +63,19 @@ public static void Initialize()
62
63
private static async void UiSettings_ColorValuesChanged ( UISettings sender , object args )
63
64
{
64
65
// 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 ) ;
73
71
}
74
72
75
73
private static void ApplyTheme ( )
76
74
{
77
75
var rootTheme = RootTheme ;
78
76
79
77
if ( App . Window . Content is FrameworkElement rootElement )
80
- {
81
78
rootElement . RequestedTheme = rootTheme ;
82
- }
83
79
84
80
if ( titleBar is not null )
85
81
{
0 commit comments