-
-
Notifications
You must be signed in to change notification settings - Fork 143
Closed
Description
macOS 13.0 introduced a new SwiftUI Scene for showing a menubar icon: MenuBarExtra.
When using the initializer with isInserted
, the settings window will just hang and show a beachball if isInserted
has a value from Defaults. If AppStorage is used, everything works as expected.
Broken code:
Note that
showPreferencesWindow
has been replaced byshowSettingsWindow
in macOS 13.0
struct TestApp: App {
@Default(.showMenuBarIcon) private var showMenubarIcon
var menuBar: some Scene {
MenuBarExtra("test", systemImage: "plus", isInserted: $showMenubarIcon) {
Button {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
} label: {
Text("Preferences")
}
.keyboardShortcut(.init(",", modifiers: .command))
Divider()
Button {
NSApp.terminate(nil)
} label: {
Text("Quit")
}
.keyboardShortcut(.init("q", modifiers: .command))
}
}
var body: some Scene {
menuBar
Settings {
PreferencesView()
}
}
}
Working code:
struct TestApp: App {
@AppStorage("showMenuBarIcon") private var showMenubarIcon = true
var menuBar: some Scene {
MenuBarExtra("test", systemImage: "plus", isInserted: $showMenubarIcon) {
Button {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
} label: {
Text("Preferences")
}
.keyboardShortcut(.init(",", modifiers: .command))
Divider()
Button {
NSApp.terminate(nil)
} label: {
Text("Quit")
}
.keyboardShortcut(.init("q", modifiers: .command))
}
}
var body: some Scene {
menuBar
Settings {
PreferencesView()
}
}
}
Metadata
Metadata
Assignees
Labels
No labels