Make the main window not closable

Question: How to make a window not closable in SwiftUI on macOS?

The solutions I’ve found so far involve going back to AppKit to instantiate an App delegate and manipulating NSWindow. Is there a more SwiftUI way?

The main window should not be closable:

  • The red close button at the top left should be disabled.
  • The File -> Close (⌘-W) menu item should be disabled.

Alternatively, closing the window should quit the app.