Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: Open multiple windows on App start on macOS

I'm trying to open two windows on App startup. One to show on another screen and the second to control the first window on my screen. Unfortunately I cannot get it running. I just tried to add a second WindowGroup, but it always just launches my first WindowGroup. I just read that this is the normal behaviour, but what is the correct way to open up two different windows on App startup?

import SwiftUI

@main
struct MyApp: App {
    
    var body: some Scene {
        WindowGroup("Test") {
            Text("Hello test")
                .frame(width: 1000, height: 1000, alignment: .center
                )
        }
        
        WindowGroup {
            ContentView()
                .frame(minWidth: 800, minHeight: 1000)
        }
    }
}
like image 527
pipo92 Avatar asked Oct 24 '25 15:10

pipo92


1 Answers

I found the solution myself with help of this answer

Instead of putting the openURL part into a Button, just add it to the onAppear call of the ContentView.

like image 98
pipo92 Avatar answered Oct 26 '25 06:10

pipo92



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!