Make appearance setting (system/light/dark) work on Mac.

This commit is contained in:
Brent Simmons committed 2026-11-06 21:44:50 -08:00
1 parent ebdf9528b1
commit 508cd969c3
6 files changed
+80 -34

No files matched your search

+13 -1
View File
@@ -24,6 +24,7 @@ enum AppDefaults {
static let unreadCountDisplay = "unreadCountDisplay"
static let timelineThumbnailsDisplay = "timelineThumbnailsDisplay"
static let timelineFeedIconsDisplay = "timelineFeedIconsDisplay"
static let userInterfaceColorPalette = "userInterfaceColorPalette"
}
/// Registered by both platforms. Each platform’s registerDefaults adds its own.
@@ -34,7 +35,8 @@ enum AppDefaults {
Key.currentThemeName: defaultThemeName,
Key.articleContentJavascriptEnabled: true,
Key.timelineThumbnailsDisplay: TimelineThumbnailsDisplay.none.rawValue,
Key.timelineFeedIconsDisplay: TimelineFeedIconsDisplay.automatic.rawValue
Key.timelineFeedIconsDisplay: TimelineFeedIconsDisplay.automatic.rawValue,
Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue
]
}
@@ -127,6 +129,16 @@ enum AppDefaults {
NotificationCenter.default.post(name: .timelineFeedIconsDisplayDidChange, object: nil)
}
}
static var userInterfaceColorPalette: UserInterfaceColorPalette {
get {
UserInterfaceColorPalette(rawValue: UserDefaults.standard.integer(forKey: Key.userInterfaceColorPalette)) ?? .automatic
}
set {
UserDefaults.standard.set(newValue.rawValue, forKey: Key.userInterfaceColorPalette)
NotificationCenter.default.post(name: .userInterfaceColorPaletteDidUpdate, object: nil)
}
}
}
// MARK: - Helpers
+30
View File
@@ -0,0 +1,30 @@
//
// UserInterfaceColorPalette.swift
// NetNewsWire
//
// Created by Brent Simmons on 11/6/26.
//
import Foundation
extension Notification.Name {
static let userInterfaceColorPaletteDidUpdate = Notification.Name("UserInterfaceColorPaletteDidUpdateNotification")
}
/// Whether the app follows the system appearance or is forced to light or dark.
enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
case automatic = 0 // Follows the system
case light = 1
case dark = 2
var description: String {
switch self {
case .automatic:
NSLocalizedString("Automatic", comment: "Automatic")
case .light:
NSLocalizedString("Light", comment: "Light")
case .dark:
NSLocalizedString("Dark", comment: "Dark")
}
}
}