macOS menubar application: main menu not being displayed

后端 未结 4 1846
Happy的楠姐
Happy的楠姐 2020-12-14 21:36

I have a statusbar application, which runs in the menu bar. Therefore I set Application is agent (UIElement) to true in the info.plst.

4条回答
  •  不思量自难忘°
    2020-12-14 21:48

    Based on the fix (or workaround) from OP. The key is really to toggle out and back to focus (thanks @Daniel!).

    Some small improvements:

    No force unwrapping, no need to set ActivationPolicy and call activate twice.

    NSApp.setActivationPolicy(.regular)
    window.makeKeyAndOrderFront(nil)    
    
    NSRunningApplication.runningApplications(withBundleIdentifier: "com.apple.dock").first?.activate(options: [])
    
    OperationQueue.current?.underlyingQueue?.asyncAfter(deadline: .now() + .milliseconds(200), execute: {
        NSApp.activate(ignoringOtherApps: true)
    })
    

提交回复
热议问题