Skip to content

Commit d73146d

Browse files
committed
fix: match SwiftUI window identifiers with hasPrefix instead of exact match
SwiftUI appends -AppWindow-N to the WindowGroup id, so window.identifier is "main-AppWindow-1" not "main". The exact match from PR #441 broke isMainWindow, preventing tab grouping and window lifecycle handling.
1 parent 4273a4d commit d73146d

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

TablePro/AppDelegate+WindowConfig.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ extension AppDelegate {
107107
}
108108

109109
func isMainWindow(_ window: NSWindow) -> Bool {
110-
window.identifier?.rawValue == WindowId.main
110+
guard let rawValue = window.identifier?.rawValue else { return false }
111+
return rawValue == WindowId.main || rawValue.hasPrefix("\(WindowId.main)-")
111112
}
112113

113114
func isWelcomeWindow(_ window: NSWindow) -> Bool {
@@ -214,12 +215,6 @@ extension AppDelegate {
214215
@objc func windowDidBecomeKey(_ notification: Notification) {
215216
guard let window = notification.object as? NSWindow else { return }
216217
let windowId = ObjectIdentifier(window)
217-
NSLog("[WindowConfig] didBecomeKey: id=%@, isMain=%d, configured=%d, title=%@, tabbing=%@",
218-
window.identifier?.rawValue ?? "nil",
219-
isMainWindow(window) ? 1 : 0,
220-
configuredWindows.contains(windowId) ? 1 : 0,
221-
window.title,
222-
window.tabbingIdentifier)
223218

224219
if isWelcomeWindow(window) && isHandlingFileOpen {
225220
window.close()
@@ -258,11 +253,10 @@ extension AppDelegate {
258253

259254
// Explicitly attach to existing tab group — automatic tabbing
260255
// doesn't work when tabbingIdentifier is set after window creation.
261-
let mainWindows = NSApp.windows.filter { $0 !== window && isMainWindow($0) && $0.isVisible }
262-
windowLogger.info(
263-
"New main window: resolved=\(resolvedIdentifier), pendingId=\(pendingId?.uuidString ?? "nil"), existing=\(mainWindows.map { $0.tabbingIdentifier })"
264-
)
265-
if let existingWindow = mainWindows.first(where: { $0.tabbingIdentifier == resolvedIdentifier }) {
256+
if let existingWindow = NSApp.windows.first(where: {
257+
$0 !== window && isMainWindow($0) && $0.isVisible
258+
&& $0.tabbingIdentifier == resolvedIdentifier
259+
}) {
266260
existingWindow.addTabbedWindow(window, ordered: .above)
267261
window.makeKeyAndOrderFront(nil)
268262
}

0 commit comments

Comments
 (0)