If the user has "Automatically hide and show the menu bar" set to "Always" in macOS settings, when using the .menuBarExtraStyle(.window)
modifier the menu bar hides when the user moves the mouse to the menu. I'm trying to prevent this from happening. This doesn't occur with .menuBarExtraStyle(.menu)
.
To try to prevent this I am removing .autoHideMenuBar
from NSApplication.shared.presentationOptions
but it is ignored and the menu bar hides anyway. I've tried this in applicationDidFinishLaunching
, the init()
method of the App struct, and also in .onHover
for the menu's view.
I'm testing with macOS 14.5. Here is a minimal example to reproduce the issue:
import SwiftUI
@main
struct UtilityApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
MenuBarExtra("Utility App", systemImage: "hammer") {
Text("Hello world")
Button("Quit") {
NSApp.terminate(nil)
}
}
.menuBarExtraStyle(.window)
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
var options = NSApplication.shared.presentationOptions
options.remove(.autoHideMenuBar)
NSApplication.shared.presentationOptions = options
}
}