@@ -31,11 +31,18 @@ private final class EditorWindow: NSWindow {
3131@MainActor
3232internal final class TabWindowController : NSWindowController , NSWindowDelegate {
3333 private static let lifecycleLogger = Logger ( subsystem: " com.TablePro " , category: " NativeTabLifecycle " )
34+ private static let frameLogger = Logger ( subsystem: " com.TablePro " , category: " WindowFrame " )
3435
3536 internal static let frameAutosaveName : NSWindow . FrameAutosaveName = " MainEditorWindow "
3637
38+ private static var frameDefaultsKey : String { " NSWindow Frame \( frameAutosaveName) " }
39+
3740 internal static var hasSavedFrame : Bool {
38- UserDefaults . standard. object ( forKey: " NSWindow Frame \( frameAutosaveName) " ) != nil
41+ UserDefaults . standard. object ( forKey: frameDefaultsKey) != nil
42+ }
43+
44+ private static func savedFrameString( ) -> String {
45+ UserDefaults . standard. string ( forKey: frameDefaultsKey) ?? " <nil> "
3946 }
4047
4148 private lazy var dataGridFieldEditor : DataGridFieldEditor = {
@@ -69,13 +76,20 @@ internal final class TabWindowController: NSWindowController, NSWindowDelegate {
6976 window. tabbingIdentifier = WindowManager . tabbingIdentifier ( for: payload. connectionId)
7077 window. collectionBehavior. insert ( [ . fullScreenPrimary, . managed] )
7178
72- window. setFrameAutosaveName ( Self . frameAutosaveName)
73- _ = window. setFrameUsingName ( Self . frameAutosaveName)
79+ Self . frameLogger. notice ( " [init] step=created savedDefaults= \( Self . savedFrameString ( ) , privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) " )
80+
81+ let didRegister = window. setFrameAutosaveName ( Self . frameAutosaveName)
82+ Self . frameLogger. notice ( " [init] step=afterSetFrameAutosaveName didRegister= \( didRegister, privacy: . public) savedDefaults= \( Self . savedFrameString ( ) , privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) " )
83+
84+ let restored = window. setFrameUsingName ( Self . frameAutosaveName)
85+ Self . frameLogger. notice ( " [init] step=afterSetFrameUsingName restored= \( restored, privacy: . public) savedDefaults= \( Self . savedFrameString ( ) , privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) " )
7486
7587 let splitVC = MainSplitViewController ( payload: payload, sessionState: sessionState)
7688 window. contentViewController = splitVC
89+ Self . frameLogger. notice ( " [init] step=afterContentVC savedDefaults= \( Self . savedFrameString ( ) , privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) " )
7790
7891 super. init ( window: window)
92+ Self . frameLogger. notice ( " [init] step=afterSuperInit savedDefaults= \( Self . savedFrameString ( ) , privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) " )
7993
8094 window. isReleasedWhenClosed = false
8195 window. delegate = self
@@ -99,13 +113,17 @@ internal final class TabWindowController: NSWindowController, NSWindowDelegate {
99113
100114 internal func windowDidResize( _ notification: Notification ) {
101115 guard let window = notification. object as? NSWindow else { return }
116+ Self . frameLogger. notice ( " [event] didResize inLive= \( window. inLiveResize, privacy: . public) windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) savedBefore= \( Self . savedFrameString ( ) , privacy: . public) " )
102117 guard !window. inLiveResize else { return }
103118 window. saveFrame ( usingName: Self . frameAutosaveName)
119+ Self . frameLogger. notice ( " [event] didResize savedAfter= \( Self . savedFrameString ( ) , privacy: . public) " )
104120 }
105121
106122 internal func windowDidEndLiveResize( _ notification: Notification ) {
107123 guard let window = notification. object as? NSWindow else { return }
124+ Self . frameLogger. notice ( " [event] didEndLiveResize windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) savedBefore= \( Self . savedFrameString ( ) , privacy: . public) " )
108125 window. saveFrame ( usingName: Self . frameAutosaveName)
126+ Self . frameLogger. notice ( " [event] didEndLiveResize savedAfter= \( Self . savedFrameString ( ) , privacy: . public) " )
109127 }
110128
111129 internal func windowDidMove( _ notification: Notification ) {
@@ -119,6 +137,7 @@ internal final class TabWindowController: NSWindowController, NSWindowDelegate {
119137 guard let window = notification. object as? NSWindow ,
120138 let coordinator = MainContentCoordinator . coordinator ( forWindow: window)
121139 else { return }
140+ Self . frameLogger. notice ( " [event] didBecomeKey windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) saved= \( Self . savedFrameString ( ) , privacy: . public) " )
122141 Self . lifecycleLogger. debug (
123142 " [switch] windowDidBecomeKey seq= \( seq) controllerId= \( self . controllerId, privacy: . public) connId= \( coordinator. connectionId, privacy: . public) "
124143 )
@@ -157,7 +176,9 @@ internal final class TabWindowController: NSWindowController, NSWindowDelegate {
157176 guard let window = notification. object as? NSWindow else { return }
158177 Self . lifecycleLogger. info ( " [close] windowWillClose seq= \( seq) controllerId= \( self . controllerId, privacy: . public) " )
159178
179+ Self . frameLogger. notice ( " [close] before saveFrame windowFrame= \( NSStringFromRect ( window. frame) , privacy: . public) savedBefore= \( Self . savedFrameString ( ) , privacy: . public) " )
160180 window. saveFrame ( usingName: Self . frameAutosaveName)
181+ Self . frameLogger. notice ( " [close] after saveFrame savedAfter= \( Self . savedFrameString ( ) , privacy: . public) " )
161182
162183 if let splitVC = window. contentViewController as? MainSplitViewController {
163184 splitVC. invalidateToolbar ( )
0 commit comments