Add baseline implementation of Automatic Termination

This commit is contained in:
Luna Razzaghipour
2025-01-30 23:15:37 +11:00
parent 04d36361b1
commit 380e3d04d3
2 changed files with 15 additions and 0 deletions

View File

@ -53,6 +53,8 @@
</dict> </dict>
<key>MDItemKeywords</key> <key>MDItemKeywords</key>
<string>Terminal</string> <string>Terminal</string>
<key>NSSupportsAutomaticTermination</key>
<true/>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<true/> <true/>
<key>NSServices</key> <key>NSServices</key>

View File

@ -234,6 +234,11 @@ extension Ghostty {
// The UTTypes that can be dragged onto this view. // The UTTypes that can be dragged onto this view.
registerForDraggedTypes(Array(Self.dropTypes)) registerForDraggedTypes(Array(Self.dropTypes))
// Disable Automatic Termination while we have a surface open,
// since an open surface means theres state the user cares about
// that cant be restored.
ProcessInfo.processInfo.disableAutomaticTermination("surface created")
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@ -261,6 +266,11 @@ extension Ghostty {
guard let surface = self.surface else { return } guard let surface = self.surface else { return }
ghostty_surface_free(surface) ghostty_surface_free(surface)
// Re-enable Automatic Termination once we know this surface is
// gone, since that means we have nothing to lose if macOS decides
// to kill us.
ProcessInfo.processInfo.enableAutomaticTermination("surface freed")
} }
/// Close the surface early. This will free the associated Ghostty surface and the view will /// Close the surface early. This will free the associated Ghostty surface and the view will
@ -275,6 +285,9 @@ extension Ghostty {
guard let surface = self.surface else { return } guard let surface = self.surface else { return }
ghostty_surface_free(surface) ghostty_surface_free(surface)
self.surface = nil self.surface = nil
// Same as the other call to this function in deinit
ProcessInfo.processInfo.enableAutomaticTermination("surface freed")
} }
func focusDidChange(_ focused: Bool) { func focusDidChange(_ focused: Bool) {