I'm converting an old macOS app to SwiftUI, and I've run into a problem with the new SwiftUI WindowGroup.
The old app is a single window application (basically a glorified timer) and an URL scheme (appname://15) can be used to change the timer.
I've attempted to recreate the old URL Scheme functionality using the onOpenURL method, but whenever the URL Scheme triggers, the app opens a new window and I can't figure out how to stop that from happening.
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
print("\(url)") // This is just debug code
})
}.commands {
CommandGroup(replacing: .newItem, addition: { })
}
}
I don't mind if the new version of the app allows multiple timers, but the url scheme is definitely not intended to open up new windows every time it's used.
How do I stop onOpenURL from launching new windows? I'm converting the app specifically to learn SwiftUI, but if it's not possible to do this behavior in SwiftUI, I'm willing to mix and match in some AppKit code.