Was trying to work out a new feature called “Windows” and ran into this issue.
- Open up a secondary window in an app (e.g. a new window that you programmatically open)
- Close the main window that your app operates in first
- Close the secondary window that your app programmatically opened
- Note that the app “exits” and you are brought back to the Home Screen
- Re-open the app
- Notice that the secondary window opens and not the main window for your app.
Looked at MacOS window behaviors and found that these APIs are not enabled for Vision OS.
https://developer.apple.com/documentation/swiftui/scene/defaultlaunchbehavior(_:)
https://developer.apple.com/documentation/swiftui/scene/defaultlaunchbehavior(_:)
Instead found this stackoverflow
Which has a comment from an Apple employee
https://developer.apple.com/forums/thread/756327
to add this workaround
var body: some Scene {
WindowGroup(id: "main") {
ContentView()
}
WindowGroup(id: "Secondary") {
SecondaryView()
.handlesExternalEvents(preferring: [], allowing: [])
}
}
The .handlesExternalEvents(preferring: [], allowing: [])
does the work of forcing the secondary to not be only one open when the app launches.
From June 2024.