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

Fix permissions for macos 15 #3497

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

DominicVonk
Copy link

Thank you for opening a PR! Please make sure that:

  • The title and description of the PR convey what the change is about, by mentioning the ticket it addresses for instance.
  • The commits messages follow the convention, so your PR can be merged.

@DominicVonk
Copy link
Author

Fixes issue #3477

}
return true
}

// workaround: public API CGPreflightScreenCaptureAccess and private API SLSRequestScreenCaptureAccess exist, but
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen this? We were not using this API because it wasn't the best in the past.

Copy link
Author

@DominicVonk DominicVonk Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I read it, I will make it that it uses it for MacOS 15+, I tested it yesterday and it works like a charm

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AltTab checks permissions continuously. The user could remove permissions at any point. We check for that on a repeating timer.

As the comment says, CGPreflightScreenCaptureAccess was returning a value which was not updated. It was a snapshot of the permissions at the time the app was launched, but didn't update after that initial snapshot.

Has this behavior changed in macOS 15? If it hasn't, then we should change other parts of the app doing the repeating timer checks. Either find another way to check there, or remove the check. But if we remove the check, we need another way to notice when the screenshot() and the AX calls start failing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to the canRecordScreen, this is updated during runtime

- Simplify `screenRecordingIsGranted_()` method by removing unnecessary `CGDisplayStream` check
- Remove `canRecordScreen()` method as it is no longer needed
- Update `screenRecordingIsGranted()` method to use the simplified `screenRecordingIsGranted_()` implementation
- Simplify `accessibilityIsGranted()` and `screenRecordingIsGranted()` methods
- Refactor `observePermissionsPostStartup()` and `observePermissionsPreStartup()` methods to improve reliability of permission checks
- Ensure permissions are granted before continuing app startup
@DominicVonk
Copy link
Author

Now I only altered the private static func screenRecordingIsGranted_()

I think this is a stable solution

@lwouis
Copy link
Owner

lwouis commented Jul 19, 2024

@DominicVonk Using CGWindowListCopyWindowInfo is what we used to do years ago.

Here's an interesting thread to read. The whole ticket is about issues with falsely detecting that the permission is gone, when it is in fact not gone.

The current implementation is solid. It has passed the test of time. It's now being challenged by changes in the latest macOS.

Here are some thoughts to go forwards:

  • We should keep the existing code for macOS < 15. It's tested and solid.
  • For macOS >= 15, I think we should look for answers in the new API (this thread also contains a lot worth reading).

@lwouis lwouis force-pushed the master branch 2 times, most recently from 7d7d9cf to 8abb9b4 Compare October 10, 2024 09:28
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

Successfully merging this pull request may close these issues.

2 participants