From 9bad9365b008633292ac271cd804a32459288686 Mon Sep 17 00:00:00 2001 From: Lukas <134181853+bo2themax@users.noreply.github.com> Date: Fri, 17 Apr 2026 15:29:29 +0200 Subject: [PATCH] macOS: open preferred config if exists --- macos/Sources/App/macOS/AppDelegate.swift | 2 +- macos/Sources/Ghostty/Ghostty.App.swift | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index f85f7ddf2..b5e73acf7 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -947,7 +947,7 @@ class AppDelegate: NSObject, // MARK: - IB Actions @IBAction func openConfig(_ sender: Any?) { - Ghostty.App.openConfig() + ghostty.openConfig() } @IBAction func reloadConfig(_ sender: Any?) { diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index cc8af71cf..992c5efb5 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -118,8 +118,14 @@ extension Ghostty { ghostty_app_tick(app) } - static func openConfig() { - let str = Ghostty.AllocatedString(ghostty_config_open_path()).string + private static func openConfig(_ app: ghostty_app_t) { + guard let app_ud = ghostty_app_userdata(app) else { return } + let app = Unmanaged.fromOpaque(app_ud).takeUnretainedValue() + app.openConfig() + } + + func openConfig() { + let str = configPath ?? Ghostty.AllocatedString(ghostty_config_open_path()).string guard !str.isEmpty else { return } #if os(macOS) let fileURL = URL(fileURLWithPath: str).absoluteString @@ -128,7 +134,7 @@ extension Ghostty { fileURL.withCString { cStr in action.url = cStr action.len = UInt(fileURL.count) - _ = openURL(action) + _ = App.openURL(action) } #else fatalError("Unsupported platform for opening config file") @@ -549,7 +555,7 @@ extension Ghostty { pwdChanged(app, target: target, v: action.action.pwd) case GHOSTTY_ACTION_OPEN_CONFIG: - openConfig() + openConfig(app) case GHOSTTY_ACTION_FLOAT_WINDOW: toggleFloatWindow(app, target: target, mode: action.action.float_window)