From 7e45f801d47b758d3889288a96fe55f8c8e4d288 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 9 Mar 2022 15:24:08 +0800 Subject: [PATCH] AppDelegate // Add a Bool to tell whether macOS is in Dark Mode. --- Source/Modules/AppDelegate.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index c0e51087..4f9aca18 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -299,4 +299,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega 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 + } }