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: media shouldn't open permissions dialog #31805

Merged
merged 2 commits into from Nov 15, 2021

Conversation

indutny
Copy link
Contributor

@indutny indutny commented Nov 12, 2021

Description of Change

Playing media shouldn't open Accessibility permissions dialog on macOS.
However, we still need to watch for media events, just not globally and
media_keys_listener_ is an API over global capture of the media keys.

The fix is to let chromium call UpdateWhichKeysAreListenedFor which
will call UpdateSystemMediaControlsEnabledControls and watch for
events on system_media_controls_ without triggering permissions popup.

Fix: #31558

cc @codebytere

Checklist

Release Notes

Notes: Fixed an issue where playing media would open Accessibility permissions dialog on macOS.

@indutny indutny requested a review from a team as a code owner November 12, 2021 09:39
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Nov 12, 2021
@indutny
Copy link
Contributor Author

indutny commented Nov 12, 2021

FWIW, I tested it on the test case from #31492 and our app. Without use of globalShortcut the playback menu on macOS looks like it did in #31492:

image

and with globalShortcut I get accessibility dialog and the shortcut is working.

@indutny
Copy link
Contributor Author

indutny commented Nov 12, 2021

@indutny
Copy link
Contributor Author

indutny commented Nov 12, 2021

It'd be great if backport to 15-x-y could be released with this change. Our weekly release pipeline is currently blocked because of this issue 😭

Playing media shouldn't open Accessibility permissions dialog on macOS.
However, we still need to watch for media events, just not globally and
`media_keys_listener_` is an API over global capture of the media keys.

The fix is to let chromium call `UpdateWhichKeysAreListenedFor` which
will call `UpdateSystemMediaControlsEnabledControls` and watch for
events on `system_media_controls_` without triggering permissions popup.
@indutny-signal
Copy link
Contributor

indutny-signal commented Nov 12, 2021

I think I messed something up while submitting the patch. Please give me few moments to figure it out. Sorry for the noise!

Nevermind, I forgot that globalShortcut won't ask for permission by itself. The code path was guarded by presence of permission and so I had to turn it on manually in order for it to work!

@indutny
Copy link
Contributor Author

indutny commented Nov 12, 2021

Added update to the patches as suggested by CircleCI.

@indutny
Copy link
Contributor Author

indutny commented Nov 12, 2021

FWIW, 13-x-y might need the back port too. We don’t use it at our company anymore, but the issue is present there as well.

thanks!

Copy link
Member

@VerteDinde VerteDinde left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @indutny!

I pulled the changes locally and tested - this patch change looks good to me, but I'd like a second opinion from another maintainer with a little more experience with the media APIs before we merge 👍

+#endif // defined(OS_MAC)
+ should_start_watching &&
+ media_keys_listener_ &&
!media_keys_listener_->StartWatchingMediaKey(key_code)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

media_keys_listener_ is implemented by ui/base/accelerators/media_keys_listener_mac.mm and it provides API for listening for media keys globally. In fact, the code in media_kes_listener_mac.mm calls CGEventTapCreate whenever new media key is watched and this immediately causes an Accessibility popup to appear since this permission is required for CGEventTapCreate to function at all.

- media_keys_listener_ = ui::MediaKeysListener::Create(
- this, ui::MediaKeysListener::Scope::kGlobal);
- DCHECK(media_keys_listener_);
- }
+ // This is required for proper functioning of MediaMetadata.
+ system_media_controls_->AddObserver(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

The trick thus is to let system_media_controls_ handle the keystroke whenever we have internal handling enabled (i.e. when there are no global accelerators assigned for a media key in electron), so we check media_key_handling_enabled_ above and fall through here if it is false (meaning that there are no accelerators in electron).

@indutny-signal
Copy link
Contributor

Thanks @VerteDinde ! I added a few comments to clarify what I've done in the patch. Hope it helps!

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Nov 13, 2021
@indutny-signal
Copy link
Contributor

Thanks for reviews, everyone!

@codebytere is there a chance you could take a look at this? You've submitted the original fix so I'd appreciate a review from you a lot 🤗

@indutny-signal
Copy link
Contributor

Fantastic, thanks @codebytere ! Please let me know if there's any additional action that I should take before this commit can be merged and backported. I'll be happy to help in any way (in part because we wish to get the update with the next 15-x-y release 😁)

@codebytere codebytere merged commit d9e93b3 into electron:main Nov 15, 2021
@release-clerk
Copy link

release-clerk bot commented Nov 15, 2021

Release Notes Persisted

Fixed an issue where playing media would open Accessibility permissions dialog on macOS.

@trop
Copy link
Contributor

trop bot commented Nov 15, 2021

I have automatically backported this PR to "15-x-y", please check out #31836

@trop
Copy link
Contributor

trop bot commented Nov 15, 2021

I have automatically backported this PR to "16-x-y", please check out #31837

@indutny-signal indutny-signal deleted the fix/gh-31558 branch November 15, 2021 13:16
@indutny-signal
Copy link
Contributor

Yaaay! Thank you!

@ArmelChesnais
Copy link

Could this be backported to 14? 14.2.1 displays the same issue.

t57ser pushed a commit to t57ser/electron that referenced this pull request Jan 25, 2022
* fix: media shouldn't open permissions dialog

Playing media shouldn't open Accessibility permissions dialog on macOS.
However, we still need to watch for media events, just not globally and
`media_keys_listener_` is an API over global capture of the media keys.

The fix is to let chromium call `UpdateWhichKeysAreListenedFor` which
will call `UpdateSystemMediaControlsEnabledControls` and watch for
events on `system_media_controls_` without triggering permissions popup.

* chore: update patches

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Playing any form of audio causes electron to ask for Accessibility permissions on macOS
7 participants