macOS menubar application: main menu not being displayed

后端 未结 4 1854
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 22:01

    This is my workaround solution for now:

    As I wrote in the question, if I click on another app and come back to my app, the menubar is being displayed. I am simulating this when I try to show the preference window:

        NSApp.setActivationPolicy(.regular)
        NSApp.activate(ignoringOtherApps: true)
        window.makeKeyAndOrderFront(nil)
    
       if (NSRunningApplication.runningApplications(withBundleIdentifier: "com.apple.dock").first?.activate(options: []))! {
           let deadlineTime = DispatchTime.now() + .milliseconds(200)
           DispatchQueue.main.asyncAfter(deadline: deadlineTime) {                 
           NSApp.setActivationPolicy(.regular)
                NSApp.activate(ignoringOtherApps: true)
           }
       }
    

    This is not a perfect solution. If I don't find a better solution, I will file a bug.

提交回复
热议问题