Post

Replies

Boosts

Views

Activity

Reply to SwiftUI MenuBarExtra not updating when State changes
I worked around this by putting the MenuBarExtra into a struct: Scene and its content into a struct: View var body: some Scene { @State var state = AppState.shared MenuBar(state: state) } private struct MenuBar: Scene { @ObservedObject var state: AppState var body: some Scene { MenuBarExtra("App Name Here", image: state.logo) { MenuBarContent(state: state) } } } private struct MenuBarContent: View { @ObservedObject var state: AppState var body: some View { Text("App Name Here") if let browser = self.state.browser { Divider() Text("Running for \(browser.getDisplayName())") } Divider() Button("Chrome") { state.setBrowser(.chrome) } Button("Firefox") { state.setBrowser(.firefox) } Button("Quit") { NSApp.terminate(nil) } } }
Sep ’24