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 updaterController: SPUStandardUpdaterController
|
||||||
let updaterDelegate: UpdaterDelegate = UpdaterDelegate()
|
let updaterDelegate: UpdaterDelegate = UpdaterDelegate()
|
||||||
|
|
||||||
|
private var appearanceObserver: NSKeyValueObservation? = nil
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
terminalManager = TerminalManager(ghostty)
|
terminalManager = TerminalManager(ghostty)
|
||||||
updaterController = SPUStandardUpdaterController(
|
updaterController = SPUStandardUpdaterController(
|
||||||
@ -96,6 +98,8 @@ class AppDelegate: NSObject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
|
updateTerminalTheme()
|
||||||
|
|
||||||
// System settings overrides
|
// System settings overrides
|
||||||
UserDefaults.standard.register(defaults: [
|
UserDefaults.standard.register(defaults: [
|
||||||
// Disable this so that repeated key events make it through to our terminal views.
|
// Disable this so that repeated key events make it through to our terminal views.
|
||||||
@ -130,6 +134,16 @@ class AppDelegate: NSObject,
|
|||||||
)
|
)
|
||||||
])
|
])
|
||||||
center.delegate = self
|
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) {
|
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.
|
/// Sync the appearance of our app with the theme specified in the config.
|
||||||
private func syncAppearance() {
|
private func syncAppearance() {
|
||||||
guard let theme = ghostty.config.windowTheme else { return }
|
guard let theme = ghostty.config.windowTheme else { return }
|
||||||
|
Reference in New Issue
Block a user