AppDelegate // Add a Bool to tell whether macOS is in Dark Mode.

This commit is contained in:
ShikiSuen 2022-03-09 15:24:08 +08:00
parent 755fa625a8
commit 0631752867
1 changed files with 15 additions and 0 deletions

View File

@ -299,4 +299,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
NSLog("vChewingErrorCallback: %@", strPrint) NSLog("vChewingErrorCallback: %@", strPrint)
} }
} }
@objc static func isDarkMode() -> Bool {
if #available(macOS 10.15, *) {
let appearanceDescription = NSApplication.shared.effectiveAppearance.debugDescription.lowercased()
if appearanceDescription.contains("dark") {
return true
}
} else if #available(macOS 10.14, *) {
if let appleInterfaceStyle = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") as? String {
if appleInterfaceStyle.lowercased().contains("dark") {
return true
}
}
}
return false
}
} }