Skip to content

Commit af55800

Browse files
authored
Merge pull request #13 from execsumo/claude/fix-system-theme-IF1KC
Fix system theme not honoring macOS dark mode
2 parents 2c33dbc + 4e9c11c commit af55800

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

Sources/Heard/MTApp.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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")

Sources/HeardCore/Views.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff 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

4277
enum 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()

0 commit comments

Comments
 (0)