feedback-assistant / reports

Open collection of Apple Feedback Assistant reports

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FB13131879: Add `NSApp.yield()` API to yield activation status back to the previously active app

sindresorhus opened this issue · comments

  • Date: 2023-09-07
  • Resolution: Open
  • Area: AppKit
  • OS: macOS 14
  • Type: Suggestion

Description

The new cooperative app activation thing in macOS 14 is great. There is one common use-case it does not cover, however. I need the ability to yield the activation status back to the previously active app.

My use-case is that I have a menu bar app. When a user clicks its menu bar icon, it opens a window and activates the app. When the user is done and clicks the menu bar item again, the app remains activated. The ideal behavior here would be that the previously activated app would regain activation status.

Maybe NSApp.yield() without any parameters would do the correct thing. So you could call it whenever you did not need activation status anymore.

Alternatively, expose the previously active app somehow, so I could call NSApp.yield(to: NSApp.previouslyActivatedApp).

My current ugly workaround is to do this when the window closes:

// Ensure we don’t hide app when other windows are open.
if !NSApp.windows.filter { /* filter out the menu bar item window */ }.contains(where: \.isVisible) {
  NSApp.hide(nil)
}