AppKit & State Restoration: Windows Auto Closing On App Quit Breaks State Restoration

I probably should know the answer to this but I don't, so I'll ask.

When I enable state restoration and have like three windows open, and I quit the app (via Quit menu, not 'Stop In Xcode') the following happens:

-NSApplication calls _closeForTermination on all the windows and this causes state restoration to fail to restore these open windows on next app launch.

This behavior is not aligned with the behavior of apps like Mail. If I have two "Viewer Windows" open in Mail and I quit the app, when I relaunch the two viewer windows are restored.

I can of course track this and write data to restore for these auto closed window myself but shouldn't there be an easy way to opt in to this behavior?

So actually in System Settings I had the "Close windows when quitting an application" preference turned on, so the behavior I was witnessing in my testing is correct.

It looks like Mail.app plays by its own rules because it decides to restore the windows anyway. It appears AppKit is doing the right thing here.

Accepted Answer

So actually in System Settings I had the "Close windows when quitting an application" preference turned on, so the behavior I was witnessing in my testing is correct.

It looks like Mail.app plays by its own rules because it decides to restore the windows anyway. It appears AppKit is doing the right thing here.

AppKit & State Restoration: Windows Auto Closing On App Quit Breaks State Restoration
 
 
Q