Open sindresorhus opened 2 years ago
@sindresorhus try NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
. Eg:
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
Settings {
Text("Hello")
}
MenuBarExtra {
Button("Bar") {
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
} label: {
Text("Foo")
}
}
}
Thanks. I am aware of the workaround.
@sindresorhus From macOS 10.14 new SettingsLink
is available to use.
https://developer.apple.com/documentation/swiftui/settingslink
Description
When you make a menu bar-only app using the new MenuBarExtra scene in SwiftUI, there’s no way to open the settings window from the menu bar window or menu since the menu bar is not available (because you have LSUIElement in Info.plist)
For example:
Possible solutions:
SettingsButton
view which is a button that simply opens the settings window.openSettings
environment value, similar to the newopenWindow
environment value *.Having a way to open the settings window is important as most apps need some kind of settings.
https://developer.apple.com/documentation/swiftui/environmentvalues/openwindow/