2

I have tried the following block in the app delegate's applicationDidStart function:

let mainScreen = NSScreen.screens[0]
window.contentView?.enterFullScreenMode(mainScreen, withOptions: nil)

This is fine, however once the app starts and enters full screen mode, there is no way to get out of it. Escape key, force quit, command q, nothing works. The only way is literally a force reboot. In mac os big sur, force reboot will open the app again in full screen mode.

This is not behaviour I want. I tried adding an onExitCommand { } block using a solution to access the NSWindow instance from within a swiftUI view (link below), but this hangs the app.

How to access own window within SwiftUI view?

I thought this would be a no nonsense and straight forward solution, but it appears to be more convoluted than expected.

Anyone have a solution?

Thanks

triple7
  • 542
  • 3
  • 17

1 Answers1

0

I encountered the same issue; using the toggleFullScreen method worked for me.

NSApplication.shared.windows.first?.toggleFullScreen(nil)
Morty
  • 1,436
  • 14
  • 12