fix(macos): use CGRequestScreenCaptureAccess instead of grabWindow for permission request#4617
Open
Mitnitsky wants to merge 1 commit intoflameshot-org:masterfrom
Open
Conversation
Contributor
Author
|
#3463 probably related |
1ada71c to
5fbe85e
Compare
Collaborator
|
This looks good to me. I want to do some testing here but I plan to merge for the actual v14 release. |
Collaborator
|
I do not get the screen permission prompt every launch, but I almost always test a from source build. Does the issue only happen when using a .dmg built in CI? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On modern macOS (especially 15+), Flameshot re-triggers the Screen Recording permission dialog on every launch. The user grants the permission, but the next time the app starts it prompts again.
Root cause
The current code uses
QScreen::grabWindow()as a hack to trigger the TCC permission prompt. This performs an actual screen capture on every launch, which modern macOS interprets as a new capture attempt rather than a no-op — re-triggering the permission dialog even when already granted.Fix
Replace the
grabWindow()hack with the proper CoreGraphics APIs:CGPreflightScreenCaptureAccess()— checks if permission is already granted (no prompt)CGRequestScreenCaptureAccess()— shows the system dialog only if not yet grantedThese APIs have been available since macOS 10.15 (Catalina) and are the documented way to handle Screen Recording permissions.