mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
HACK: dynamic light/dark theme
This commit is contained in:
@ -72,6 +72,8 @@ class AppDelegate: NSObject,
|
||||
let updaterController: SPUStandardUpdaterController
|
||||
let updaterDelegate: UpdaterDelegate = UpdaterDelegate()
|
||||
|
||||
private var appearanceObserver: NSKeyValueObservation? = nil
|
||||
|
||||
override init() {
|
||||
terminalManager = TerminalManager(ghostty)
|
||||
updaterController = SPUStandardUpdaterController(
|
||||
@ -96,6 +98,8 @@ class AppDelegate: NSObject,
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
updateTerminalTheme()
|
||||
|
||||
// System settings overrides
|
||||
UserDefaults.standard.register(defaults: [
|
||||
// Disable this so that repeated key events make it through to our terminal views.
|
||||
@ -130,6 +134,16 @@ class AppDelegate: NSObject,
|
||||
)
|
||||
])
|
||||
center.delegate = self
|
||||
|
||||
appearanceObserver = NSApp.observe(\.effectiveAppearance, options: [.new, .old]) { [weak self] app, change in
|
||||
guard let self else { return }
|
||||
if change.newValue?.name == change.oldValue?.name {
|
||||
return
|
||||
}
|
||||
|
||||
self.updateTerminalTheme()
|
||||
self.reloadConfig(nil)
|
||||
}
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ notification: Notification) {
|
||||
@ -394,6 +408,13 @@ class AppDelegate: NSObject,
|
||||
}
|
||||
}
|
||||
|
||||
private func updateTerminalTheme() {
|
||||
let configDir = "\(NSHomeDirectory())/.config/ghostty"
|
||||
let currentTheme = NSApp.effectiveAppearance.name == .darkAqua ? "dark" : "light"
|
||||
unlink("\(configDir)/theme")
|
||||
symlink("\(configDir)/theme-\(currentTheme)", "\(configDir)/theme")
|
||||
}
|
||||
|
||||
/// Sync the appearance of our app with the theme specified in the config.
|
||||
private func syncAppearance() {
|
||||
guard let theme = ghostty.config.windowTheme else { return }
|
||||
|
Reference in New Issue
Block a user