Open sindresorhus opened 1 year ago
Totally agree with this need. I have a Document-based MacOS app that also has a Splash-screen startup Window. I need that window to open at startup but it won't unless it is located first in body{} before the DocumentGroup. But if it is first, then other parts of UI (the Cmd-N shortcut on File->New menu) stop working. We either need the ability to control what opens at App startup, or we need the ability to programmatically open windows, as from the AppDelegate, or init(). Currently I can make this work but the system emits the serious looking warning every time the program starts up.
@tommcoates This repo is a manual mirror of Feedback Assistant reports. Apple will not see your comment. Submit a duplicate of this report to Apple with your added comments.
Description
Currently, if you try to use it in's value outside of being installed on a View. This will always read the default value and will not update.
App
, you get a warning: Accessing EnvironmentThe use-cases for needing this are:
MenuBarExtra
andWindow
and you want to open theWindow
at launch. TheWindow
could be a welcome screen.My specific use-case is to show a custom notification window at certain times. Currently, I have to use an AppKit window for this as it’s not possible to open a
Window
outside of being in a SwiftUI view, and my app is mixed SwiftUI and AppKit. Another use-case I have is to be able to open aWindow
from a AppKit style menu bar app (MenuBarExtra is still too limited to use for most use-cases).The SwiftUI window system is currently only optimized for a perfect future where everything is inside a SwiftUI view lifecycle, but this won’t be reality for most apps for many years.
Alternatively, provide a method to open SwiftUI windows based on their identifier from anywhere, not from the
openAction
environment value.Example: