File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,15 +89,15 @@ struct HeardApp: App {
8989 var body : some Scene {
9090 MenuBarExtra {
9191 MenuBarView ( model: appModel)
92- . preferredColorScheme ( appModel. settingsStore. settings. appearance. colorScheme )
92+ . heardAppearance ( appModel. settingsStore. settings. appearance)
9393 } label: {
9494 MenuBarIcon ( model: appModel)
9595 }
9696 . menuBarExtraStyle ( . window)
9797
9898 Window ( " Heard Settings " , id: " settings " ) {
9999 SettingsView ( model: appModel)
100- . preferredColorScheme ( appModel. settingsStore. settings. appearance. colorScheme )
100+ . heardAppearance ( appModel. settingsStore. settings. appearance)
101101 . onAppear { WindowActivationCoordinator . begin ( " settings " ) }
102102 . onDisappear { WindowActivationCoordinator . end ( " settings " ) }
103103 }
@@ -106,7 +106,7 @@ struct HeardApp: App {
106106
107107 Window ( " Name Speakers " , id: " speaker-naming " ) {
108108 SpeakerNamingView ( model: appModel)
109- . preferredColorScheme ( appModel. settingsStore. settings. appearance. colorScheme )
109+ . heardAppearance ( appModel. settingsStore. settings. appearance)
110110 . onAppear { WindowActivationCoordinator . begin ( " speaker-naming " ) }
111111 . onDisappear {
112112 WindowActivationCoordinator . end ( " speaker-naming " )
Original file line number Diff line number Diff line change @@ -37,6 +37,41 @@ public extension AppAppearance {
3737 }
3838}
3939
40+ // MARK: - Appearance Modifier
41+
42+ private struct AppearanceModifier : ViewModifier {
43+ let appearance : AppAppearance
44+ @State private var systemIsDark = NSApp . effectiveAppearance. bestMatch ( from: [ . darkAqua, . aqua] ) == . darkAqua
45+
46+ func body( content: Content ) -> some View {
47+ content
48+ . preferredColorScheme ( resolvedScheme)
49+ . onReceive (
50+ DistributedNotificationCenter . default ( )
51+ . publisher ( for: NSNotification . Name ( " AppleInterfaceThemeChangedNotification " ) )
52+ ) { _ in
53+ // Short delay: effectiveAppearance may not yet reflect the change
54+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) {
55+ systemIsDark = NSApp . effectiveAppearance. bestMatch ( from: [ . darkAqua, . aqua] ) == . darkAqua
56+ }
57+ }
58+ }
59+
60+ private var resolvedScheme : ColorScheme ? {
61+ switch appearance {
62+ case . system: systemIsDark ? . dark : . light
63+ case . light: . light
64+ case . dark: . dark
65+ }
66+ }
67+ }
68+
69+ public extension View {
70+ func heardAppearance( _ appearance: AppAppearance ) -> some View {
71+ modifier ( AppearanceModifier ( appearance: appearance) )
72+ }
73+ }
74+
4075// MARK: - Theme
4176
4277enum HeardTheme {
@@ -2150,7 +2185,6 @@ public struct SpeakerNamingView: View {
21502185 }
21512186 . frame ( width: 560 )
21522187 . background ( HeardTheme . Paper. bg)
2153- . preferredColorScheme ( . light)
21542188 . onAppear { startCountdown ( ) }
21552189 . onDisappear {
21562190 stopAudio ( )
You can’t perform that action at this time.
0 commit comments