From cdbf16e13bbdc7e634891613f5c33c9d67d75475 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 20 Sep 2023 11:10:46 -0700 Subject: [PATCH] macos: set env var for app bundle to detect app launch vs CLI --- macos/Ghostty-Info.plist | 7 ++++++- macos/Ghostty.xcodeproj/project.pbxproj | 4 ++++ macos/Sources/AppDelegate.swift | 1 - macos/Sources/main.swift | 12 ++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 macos/Sources/main.swift diff --git a/macos/Ghostty-Info.plist b/macos/Ghostty-Info.plist index 0c67376eb..de2c98bf9 100644 --- a/macos/Ghostty-Info.plist +++ b/macos/Ghostty-Info.plist @@ -1,5 +1,10 @@ - + + GHOSTTY_MAC_APP + 1 + LSEnvironment + + diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index a2d86af81..87e4ca7ed 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ A5CEAFDC29B8009000646FDA /* SplitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CEAFDB29B8009000646FDA /* SplitView.swift */; }; A5CEAFDE29B8058B00646FDA /* SplitView.Divider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CEAFDD29B8058B00646FDA /* SplitView.Divider.swift */; }; A5CEAFFF29C2410700646FDA /* Backport.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CEAFFE29C2410700646FDA /* Backport.swift */; }; + A5FEB3002ABB69450068369E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FEB2FF2ABB69450068369E /* main.swift */; }; A5FECBD729D1FC3900022361 /* PrimaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FECBD629D1FC3900022361 /* PrimaryView.swift */; }; A5FECBD929D2010400022361 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FECBD829D2010400022361 /* WindowAccessor.swift */; }; /* End PBXBuildFile section */ @@ -65,6 +66,7 @@ A5CEAFDD29B8058B00646FDA /* SplitView.Divider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitView.Divider.swift; sourceTree = ""; }; A5CEAFFE29C2410700646FDA /* Backport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Backport.swift; sourceTree = ""; }; A5D495A1299BEC7E00DD1313 /* GhosttyKit.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = GhosttyKit.xcframework; sourceTree = ""; }; + A5FEB2FF2ABB69450068369E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; A5FECBD629D1FC3900022361 /* PrimaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryView.swift; sourceTree = ""; }; A5FECBD829D2010400022361 /* WindowAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowAccessor.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -128,6 +130,7 @@ A54CD6ED299BEB14008C95BB /* Sources */ = { isa = PBXGroup; children = ( + A5FEB2FF2ABB69450068369E /* main.swift */, A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */, 857F63802A5E64F200CA4815 /* MainMenu.xib */, A53426362A7DC53000EBB7A2 /* Features */, @@ -279,6 +282,7 @@ A55B7BBC29B6FC330055DE60 /* SurfaceView.swift in Sources */, A59444F729A2ED5200725BBA /* SettingsView.swift in Sources */, A5FECBD729D1FC3900022361 /* PrimaryView.swift in Sources */, + A5FEB3002ABB69450068369E /* main.swift in Sources */, A55B7BB829B6F53A0055DE60 /* Package.swift in Sources */, A55B7BBE29B701360055DE60 /* Ghostty.SplitView.swift in Sources */, A55B7BB629B6F47F0055DE60 /* AppState.swift in Sources */, diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index e412de441..ebf728d83 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -2,7 +2,6 @@ import AppKit import OSLog import GhosttyKit -@NSApplicationMain class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyAppStateDelegate { // The application logger. We should probably move this at some point to a dedicated // class/struct but for now it lives here! 🤷‍♂️ diff --git a/macos/Sources/main.swift b/macos/Sources/main.swift new file mode 100644 index 000000000..ee38c8d55 --- /dev/null +++ b/macos/Sources/main.swift @@ -0,0 +1,12 @@ +import AppKit +import Cocoa + +// We put the GHOSTTY_MAC_APP env var into the Info.plist to detect +// whether we launch from the app or not. A user can fake this if +// they want but they're doing so at their own detriment... +let process = ProcessInfo.processInfo +if (process.environment["GHOSTTY_MAC_APP"] == "") { + AppDelegate.logger.warning("NOT IN THE MAC APP") +} + +_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)