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

Rule Request: Disallow NSApp.activate(ignoringOtherApps: true) in applicationDidFinishLaunching #2643

Open
2 tasks done
sindresorhus opened this issue Feb 13, 2019 · 0 comments

Comments

@sindresorhus
Copy link

New Issue Checklist

New rule request

Most macOS apps abuse this method. The problem is the ignoringOtherApps: true part. It means if you launch the app and then switch to a different app while it's launching, it will steal focus when it has finished launching. This is something that is hard to catch in development, but users gets annoyed by this behavior.

I propose reporting when NSApp.activate(ignoringOtherApps: true) is used inside applicationDidFinishLaunching. It's ok to use ignoringOtherApps: true in other situations. It's also ok to use NSApp.activate(ignoringOtherApps: false) inside applicationDidFinishLaunching.

Having this rule will hopefully make devs aware they're using the API incorrectly and fix their apps.

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

Because it's a widespread problem that affects real users: https://twitter.com/sindresorhus/status/1085002325511426051

  1. Provide several examples of what would and wouldn't trigger violations.

Would trigger:

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
	func applicationDidFinishLaunching(_ notification: Notification) {
		NSApp.activate(ignoringOtherApps: true)
	}
}

Would not trigger:

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
	func applicationDidFinishLaunching(_ notification: Notification) {
		NSApp.activate(ignoringOtherApps: false)
	}
}
@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
	func foo() {
		NSApp.activate(ignoringOtherApps: true)
	}
}
  1. Should the rule be configurable, if so what parameters should be configurable?

No.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a rule as opt-in.

Enabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants