Last active
February 11, 2022 14:20
-
-
Save avaidyam/6d0e3605cf85b10f4d0f9d654518e984 to your computer and use it in GitHub Desktop.
Animated dark mode transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swiftc this file & mv to /usr/local/bin | |
import Cocoa | |
typealias NSGlobalPreferenceTransitionBlock = @convention(block) () -> Void | |
@objc protocol NSGlobalPreferenceTransitionProtocol: NSObjectProtocol { | |
static func transition() -> AnyObject | |
func waitForTransitionWithCompletionHandler(_ arg1: @escaping NSGlobalPreferenceTransitionBlock) | |
func postChangeNotification(_ arg1: UInt64, completionHandler arg2: @escaping NSGlobalPreferenceTransitionBlock) | |
} | |
let NSGlobalPreferenceTransition: AnyClass = NSClassFromString("NSGlobalPreferenceTransition")! | |
let libSkyLight = dlopen("/System/Library/PrivateFrameworks/SkyLight.framework/Skylight", RTLD_LAZY) | |
let SLSGetAppearanceThemeLegacy = unsafeBitCast(dlsym( | |
libSkyLight, | |
"SLSGetAppearanceThemeLegacy" | |
), to: (@convention (c) () -> Bool).self) | |
let SLSSetAppearanceThemeLegacy = unsafeBitCast(dlsym( | |
libSkyLight, | |
"SLSSetAppearanceThemeLegacy" | |
), to: (@convention (c) (Bool) -> Void).self) | |
let SLSSetAppearanceThemeNotifying = unsafeBitCast(dlsym( | |
libSkyLight, | |
"SLSSetAppearanceThemeNotifying" | |
), to: (@convention (c) (Bool, Bool) -> Void).self) | |
DispatchQueue.main.async { | |
SLSSetAppearanceThemeNotifying(!SLSGetAppearanceThemeLegacy(), false) | |
let transition: AnyObject? = NSGlobalPreferenceTransition.transition() | |
transition?.postChangeNotification(0, completionHandler: {}) | |
transition?.waitForTransitionWithCompletionHandler { exit(0) } | |
} | |
NSApplication.shared.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment