How to restore the last window size on Mac Catalyst

I noticed that sometimes, when opening my Mac Catalyst app, the window is not resized to the size I left it the last time.

Should I restore it manually when launching the app, or is the system responsible for it? And if it so, why it doesn't work sometimes?

The OS generally takes care of this for you. If your app is a single-scene app, the window frame is always restored on launch. Alternatively, if your app has opted into UIApplicationSupportsMultipleScenes, the window restoration behavior follows the setting under System Preferences -> General -> Close windows when quitting an app. In this case, Cmd-Opt-Q will invert the behavior. If all windows were closed as a part of app termination (or if no windows existed at termination), a single new UIWindowScene is created when the app is next launched.

Similar question, but specific to restoring window size and position after closing using the red stoplight button: https://developer.apple.com/forums/thread/767546

How to restore the last window size on Mac Catalyst
 
 
Q