Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sindresorhus opened this issue Sep 7, 2023 · 0 comments

Comments

@sindresorhus
Copy link
Member

  • 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant