macos: just some textual cleanup

This commit is contained in:
Mitchell Hashimoto
2026-02-25 08:27:10 -08:00
parent 58acab6c7d
commit 304823d560
4 changed files with 13 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
// C imports here are exposed to Swift.
#import "VibrantLayer.h"
#import "ObjCExceptionCatcher.h"
#import "VibrantLayer.h"

View File

@@ -41,7 +41,8 @@ extension NSWindow {
}
/// Wraps `addTabbedWindow` with an Objective-C exception catcher because AppKit can
/// occasionally throw NSExceptions in visual tab picker flows.
/// throw NSExceptions in visual tab picker flows. Swift cannot safely recover from
/// those exceptions, so we route through Obj-C and log a recoverable failure.
@discardableResult
func addTabbedWindowSafely(
_ child: NSWindow,
@@ -49,10 +50,8 @@ extension NSWindow {
) -> Bool {
var error: NSError?
let success = GhosttyAddTabbedWindowSafely(self, child, ordered.rawValue, &error)
if let error {
let reason = error.localizedDescription
Ghostty.logger.error("addTabbedWindow failed: \(reason)")
Ghostty.logger.error("addTabbedWindow failed: \(error.localizedDescription)")
}
return success

View File

@@ -1,9 +1,13 @@
#import <Foundation/Foundation.h>
/// Minimal Objective-C exception bridge for AppKit tabbing APIs.
/// This file contains wrappers around various ObjC functions so we can catch
/// exceptions, since you can't natively catch ObjC exceptions from Swift
/// (at least at the time of writing this comment).
/// NSWindow.addTabbedWindow wrapper
FOUNDATION_EXPORT BOOL GhosttyAddTabbedWindowSafely(
id parent,
id child,
id _Nonnull parent,
id _Nonnull child,
NSInteger ordered,
NSError * _Nullable * _Nullable error
);

View File

@@ -12,6 +12,8 @@ BOOL GhosttyAddTabbedWindowSafely(
NSError * _Nullable * _Nullable error
) {
#if TARGET_OS_OSX
// AppKit occasionally throws NSException while reparenting tabbed windows.
// We must catch it in Objective-C; letting this cross into Swift is unsafe.
@try {
[((NSWindow *)parent) addTabbedWindow:(NSWindow *)child ordered:(NSWindowOrderingMode)ordered];
return YES;