I'd like to support multiple windows in my macOS app, which provides previews of cameras in the system, using the SwiftUI app life cycle, on macOS 13.5.2 and later.
I can make multiple window without any problem, using the default behavior of WindowGroup and the File/New menu item.
WindowGroup(id: "main-viewer", for: String.self) { $cameraUniqueID in
ContentView(cameraUniqueID: cameraUniqueID)
I can make a specific window on a camera using the .openWindow environment variable:
.openWindow(id: "main-viewer", value:someSpecificCameraID)
What I would like to be able to do is change the 'value' of my window at run time. When a user chooses "New Window", they get a window with a view of the first (or default) camera in it. They can then choose another camera to show in that window. I would like to be able to persist the chosen camera and the position and size of that window (originally opened with File/New Window).
Windows opened with New Window are always opened with a nil value.
Windows opened with .openWindow have their size and content saved, but I don't want to add UI to open specific windows. I want to open a generic window, then specify what camera it is looking at, move and resize it, and I'd like to save that window state.
Is this possible, or am I holding SwiftUI wrong?