Define main window in visionOS

Hello everyone!

For applications with multiple windows, if I close all open windows, I've noticed that visionOS reopen only the last closed window when launching the app again from the menu.

Is there a way I can set a main window that will always be open when the application is launched?

Replies

Did you ever figure this out? I'm running into the same issue.

And even if the first window to open includes openWindow commands, they seem to not execute, as is the case when the LaunchView is the first to open when relaunching this example app. My Application Scene Manifest's (UIApplicationSceneManifest) Preferred Default Scene Session Role (UIApplicationPreferredDefaultSceneSessionRole) is Window Application Session (UIWindowSceneSessionRoleApplication).

import SwiftUI


@main
struct ExampleApp: App {
    var body: some Scene {
        WindowGroup {
            LaunchView()
        }
        
        WindowGroup(id: "GameControlWindow") {
            GameControlWindow()
                .padding()
        }
        
        WindowGroup(id: "GameVolume") {
            GameView()
        }
        .windowStyle(.volumetric)
    }
}


struct LaunchView: View {
    @Environment(\.openWindow) var openWindow
    
    var body: some View {
        EmptyView()
            .onAppear() {
                openWindow(id: "GameControlWindow")
                openWindow(id: "GameVolume")
            }
    }
}