From 6fed7cde1907cdd62eaa3a2f297301bdee15db10 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 Dec 2023 19:28:06 -0800 Subject: [PATCH] macos: do not open an initial window if opening from URL --- macos/Sources/AppDelegate.swift | 9 ++++++--- macos/Sources/Features/Terminal/TerminalManager.swift | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index 600038963..b99d45ba8 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -78,9 +78,12 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti "ApplePressAndHoldEnabled": false, ]) - // Let's launch our first window. - // TODO: we should detect if we restored windows and if so not launch a new window. - terminalManager.newWindow() + // Let's launch our first window. We only do this if we have no other windows. It + // is possible to have other windows if we're opening a URL since `application(_:openFile:)` + // is called before this. + if (terminalManager.windows.count == 0) { + terminalManager.newWindow() + } // Initial config loading configDidReload(ghostty) diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index fc4183864..1720c4a10 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -17,7 +17,7 @@ class TerminalManager { var focusedSurface: Ghostty.SurfaceView? { mainWindow?.controller.focusedSurface } /// The set of windows we currently have. - private var windows: [Window] = [] + var windows: [Window] = [] // Keep track of the last point that our window was launched at so that new // windows "cascade" over each other and don't just launch directly on top