CocoaImpl // Fix isDarkMode().

This commit is contained in:
ShikiSuen 2024-02-26 23:54:54 +08:00
parent c2679735c1
commit d5d9167b1e
1 changed files with 7 additions and 8 deletions

View File

@ -128,15 +128,14 @@ public extension NSApplication {
// MARK: - System Dark Mode Status Detector. // MARK: - System Dark Mode Status Detector.
static var isDarkMode: Bool { static var isDarkMode: Bool {
if #unavailable(macOS 10.14) { return false } // "NSApp" can be nil during SPM unit tests.
if #available(macOS 10.15, *) { // Therefore, the method dedicated for macOS 10.15 and later is not considered stable anymore.
let appearanceDescription = NSApp.effectiveAppearance.debugDescription // Fortunately, the method for macOS 10.14 works well on later macOS releases.
.lowercased() if #available(macOS 10.14, *), let strAIS = UserDefaults.current.string(forKey: "AppleInterfaceStyle") {
return appearanceDescription.contains("dark") return strAIS.lowercased().contains("dark")
} else if let appleInterfaceStyle = UserDefaults.current.string(forKey: "AppleInterfaceStyle") { } else {
return appleInterfaceStyle.lowercased().contains("dark") return false
} }
return false
} }
// MARK: - Tell whether this IME is running with Root privileges. // MARK: - Tell whether this IME is running with Root privileges.