At this answer the solution work for Scene plus swiftUI.
However using @main like:
@main
struct MyApp: App {
@StateObject private var model = MyModel()
var body: some Scene {
WindowGroup {
Router {
AppContent()
}.environmentObject(self.model)
}
}
}
I also tried to get the main window by using
var window: NSWindow? {
let window = NSApplication.shared.mainWindow
return window
}
Nevertheless, the mainWindow
always return nil
Update:
I need the NSWindow
due to the need of conforming with ASWebAuthenticationPresentationContextProviding
which obligates to return a NSWindow
. Basically, I'm trying to do something like:
LoginView(store: AuthStore(window: window))
Where AuthStore
uses the AuthenticationServices
to perform an authentication.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…