Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/decodex-app/Sources/DecodexApp/AccountPanelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ struct OperatorFlowMetricView: View {
private var valueTint: Color {
metric.value > 0
? metric.tint
: PanelPalette.secondaryText(colorScheme).opacity(colorScheme == .dark ? 0.64 : 0.72)
: PanelPalette.primaryText(colorScheme).opacity(colorScheme == .dark ? 0.76 : 0.66)
}
}

Expand Down
36 changes: 36 additions & 0 deletions apps/decodex-app/Sources/DecodexApp/DecodexApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}

@MainActor
final class AppAppearanceStore: ObservableObject {
@Published private(set) var colorScheme = AppAppearanceStore.currentColorScheme()
private var observation: NSKeyValueObservation?

init() {
colorScheme = Self.currentColorScheme()
observation = NSApp.observe(\.effectiveAppearance, options: [.new]) { [weak self] _, _ in
Task { @MainActor in
self?.colorScheme = Self.currentColorScheme()
}
}
}

private static func currentColorScheme() -> ColorScheme {
let darkAppearances: [NSAppearance.Name] = [
.darkAqua,
.vibrantDark,
.accessibilityHighContrastDarkAqua,
.accessibilityHighContrastVibrantDark,
]
let lightAppearances: [NSAppearance.Name] = [
.aqua,
.vibrantLight,
.accessibilityHighContrastAqua,
.accessibilityHighContrastVibrantLight,
]
let match = NSApp.effectiveAppearance.bestMatch(from: darkAppearances + lightAppearances)

return darkAppearances.contains { $0 == match } ? .dark : .light
}
}

enum AppAssets {
static let statusBarIcon: NSImage = {
let image = NSImage(named: "StatusBarIcon")
Expand All @@ -29,6 +62,7 @@ final class LoginWindowState: ObservableObject {
@main
struct DecodexApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@StateObject private var appAppearance = AppAppearanceStore()
@StateObject private var store: AccountStore
@StateObject private var loginWindowState = LoginWindowState()

Expand Down Expand Up @@ -59,6 +93,8 @@ struct DecodexApp: App {
@ViewBuilder
private var menuBarContent: some View {
let content = AccountPanelView(store: store, loginWindowState: loginWindowState)
.environment(\.colorScheme, appAppearance.colorScheme)
.preferredColorScheme(appAppearance.colorScheme)
.task {
await store.refreshIfNeeded()
store.startOperatorSnapshotStream()
Expand Down