Skip to content

Present MenuBarExtra window on app launch? #5

Answered by orchetect
andrewtheis asked this question in Q&A
Discussion options

You must be logged in to vote

Doing things on app launch with SwiftUI is tricky.

One issue may be that AppState is a global singleton when it should probably only be instanced in MyApp and passed by environment to child views.

It’s better if you are able to mutate SwiftUI state from within a SwiftUI context.

There is a slightly clunky way but it works:

@main struct MyApp: App {
    @Environment(\.scenePhase) private var scenePhase
    @State private var isLaunched: Bool = false
    @ObservedObject var appState = AppState()
   
    var body: some Scene {
        MenuBarExtra("MyApp", systemImage: "music.note.tv") {
            MenuBarExtraView()
                .frame(minWidth: 800)
        }
        .menuBarExtraStyle(.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by orchetect
Comment options

You must be logged in to vote
1 reply
@orchetect
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants