mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Make appearance setting (system/light/dark) work on Mac.
This commit is contained in:
1 parent
ebdf9528b1
commit
508cd969c3
6 files changed
+80
-34
No files matched your search
@@ -121,6 +121,7 @@ let appName = "NetNewsWire"
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: AccountManager.shared)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleUnreadCountDisplaySettingDidChange(_:)), name: .unreadCountDisplaySettingDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleUserInterfaceColorPaletteDidUpdate(_:)), name: .userInterfaceColorPaletteDidUpdate, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(inspectableObjectsDidChange(_:)), name: .InspectableObjectsDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(importDownloadedTheme(_:)), name: .didEndDownloadingTheme, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeImportError(_:)), name: .didFailToImportThemeWithError, object: nil)
|
||||
@@ -144,6 +145,7 @@ let appName = "NetNewsWire"
|
||||
|
||||
func applicationWillFinishLaunching(_ notification: Notification) {
|
||||
FaviconGenerator.templateImage = Assets.Images.faviconTemplate
|
||||
applyUserInterfaceColorPalette()
|
||||
|
||||
installAppleEventHandlers()
|
||||
|
||||
@@ -366,6 +368,10 @@ let appName = "NetNewsWire"
|
||||
updateDockBadge()
|
||||
}
|
||||
|
||||
@objc func handleUserInterfaceColorPaletteDidUpdate(_ notification: Notification) {
|
||||
applyUserInterfaceColorPalette()
|
||||
}
|
||||
|
||||
@objc func inspectableObjectsDidChange(_ note: Notification) {
|
||||
MainActor.assumeIsolated {
|
||||
guard let inspectorWindowController = inspectorWindowController, inspectorWindowController.isOpen else {
|
||||
@@ -1058,6 +1064,17 @@ extension AppDelegate: NSWindowRestoration {
|
||||
|
||||
private extension AppDelegate {
|
||||
|
||||
func applyUserInterfaceColorPalette() {
|
||||
switch AppDefaults.userInterfaceColorPalette {
|
||||
case .automatic:
|
||||
NSApp.appearance = nil
|
||||
case .light:
|
||||
NSApp.appearance = NSAppearance(named: .aqua)
|
||||
case .dark:
|
||||
NSApp.appearance = NSAppearance(named: .darkAqua)
|
||||
}
|
||||
}
|
||||
|
||||
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
|
||||
handleStatusNotification(userInfo: userInfo, statusKey: .read)
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ final class AppearancePreferencesViewController: NSViewController {
|
||||
|
||||
override func viewWillAppear() {
|
||||
super.viewWillAppear()
|
||||
updateAppearancePopup()
|
||||
updateArticleThemePopup()
|
||||
}
|
||||
|
||||
@@ -64,8 +65,19 @@ final class AppearancePreferencesViewController: NSViewController {
|
||||
updateArticleThemePopup()
|
||||
}
|
||||
|
||||
@objc func handleUserInterfaceColorPaletteDidUpdate(_ notification: Notification) {
|
||||
updateAppearancePopup()
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func appearancePopUpDidChange(_ sender: Any) {
|
||||
guard let tag = appearancePopup?.selectedTag(), let colorPalette = UserInterfaceColorPalette(rawValue: tag) else {
|
||||
return
|
||||
}
|
||||
AppDefaults.userInterfaceColorPalette = colorPalette
|
||||
}
|
||||
|
||||
@IBAction func showThemesFolder(_ sender: Any) {
|
||||
let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)
|
||||
NSWorkspace.shared.open(url)
|
||||
@@ -87,6 +99,7 @@ private extension AppearancePreferencesViewController {
|
||||
func commonInit() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleApplicationWillBecomeActive(_:)), name: NSApplication.willBecomeActiveNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleArticleThemeNamesDidChange(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleUserInterfaceColorPaletteDidUpdate(_:)), name: .userInterfaceColorPaletteDidUpdate, object: nil)
|
||||
}
|
||||
|
||||
/// On macOS 15 the "Article Text Size:" label is vertically misaligned
|
||||
@@ -120,6 +133,10 @@ private extension AppearancePreferencesViewController {
|
||||
}
|
||||
}
|
||||
|
||||
func updateAppearancePopup() {
|
||||
appearancePopup?.selectItem(withTag: AppDefaults.userInterfaceColorPalette.rawValue)
|
||||
}
|
||||
|
||||
func updateArticleThemePopup() {
|
||||
guard let articleThemePopup, let menu = articleThemePopup.menu else {
|
||||
return
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="apK-10-0k1"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="appearancePopUpDidChange:" target="-2" id="apA-cM-0a1"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="sp1-Bx-0s1">
|
||||
<rect key="frame" x="0.0" y="556" width="383" height="5"/>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,31 +13,12 @@ import Account
|
||||
import Articles
|
||||
import Images
|
||||
|
||||
enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
|
||||
case automatic = 0
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
public static let userInterfaceColorPaletteDidUpdate = Notification.Name("UserInterfaceColorPaletteDidUpdateNotification")
|
||||
public static let timelineIconSizeDidChange = Notification.Name("TimelineIconSizeDidChangeNotification")
|
||||
public static let timelineNumberOfLinesDidChange = Notification.Name("TimelineNumberOfLinesDidChangeNotification")
|
||||
}
|
||||
|
||||
extension AppDefaults.Key {
|
||||
static let userInterfaceColorPalette = "userInterfaceColorPalette"
|
||||
static let refreshClearsReadArticles = "refreshClearsReadArticles"
|
||||
static let timelineNumberOfLines = "timelineNumberOfLines"
|
||||
static let timelineIconDimension = "timelineIconSize"
|
||||
@@ -69,19 +50,6 @@ extension AppDefaults {
|
||||
|
||||
fileprivate static let logger = Logger(subsystem: Logger.nnwSubsystem, category: "AppDefaults")
|
||||
|
||||
static var userInterfaceColorPalette: UserInterfaceColorPalette {
|
||||
get {
|
||||
if let result = UserInterfaceColorPalette(rawValue: UserDefaults.standard.integer(forKey: Key.userInterfaceColorPalette)) {
|
||||
return result
|
||||
}
|
||||
return .automatic
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.userInterfaceColorPalette)
|
||||
NotificationCenter.default.post(name: .userInterfaceColorPaletteDidUpdate, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
static var useSystemBrowser: Bool {
|
||||
get {
|
||||
UserDefaults.standard.bool(forKey: Key.useSystemBrowser)
|
||||
@@ -341,7 +309,6 @@ extension AppDefaults {
|
||||
migrateAppGroupDefaultsIfNeeded()
|
||||
|
||||
let platformDefaults: [String: Any] = [
|
||||
Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
|
||||
Key.refreshClearsReadArticles: false,
|
||||
Key.timelineNumberOfLines: 2,
|
||||
Key.timelineIconDimension: IconSize.medium.rawValue,
|
||||
|
||||
Reference in new issue
Block a user