My VisionOS App (Travel Immersive) has two interface windows: a main 2D interface window and a 3D Earth window. If the user first closes the main interface window and then the Earth window, clicking the app icon again will only launch the Earth window while failing to display the main interface window. However, if the user closes the Earth window first and then the main interface window, the app restarts normally.
Below is the code of
import SwiftUI
@main struct Travel_ImmersiveApp: App { @StateObject private var appModel = AppModel()
var body: some Scene {
WindowGroup(id: "MainWindow") {
ContentView()
.environmentObject(appModel)
.onDisappear {
appModel.closeEarthWindow = true
}
}
.windowStyle(.automatic)
.defaultSize(width: 1280, height: 825)
WindowGroup(id: "Earth") {
if !appModel.closeEarthWindow {
Globe3DView()
.environmentObject(appModel)
.onDisappear {
appModel.isGlobeWindowOpen = false
}
} else {
EmptyView() // 关闭时渲染空视图
}
}
.windowStyle(.volumetric)
.defaultSize(width: 0.8, height: 0.8, depth: 0.8, in: .meters)
ImmersiveSpace(id: "ImmersiveView") {
ImmersiveView()
.environmentObject(appModel)
}
}
}