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

feat: add media access apis for mojave #15624

Merged
merged 1 commit into from Dec 4, 2018
Merged

feat: add media access apis for mojave #15624

merged 1 commit into from Dec 4, 2018

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Nov 7, 2018

Description of Change

This PR adds new APIs to control new media privacy and consent rules introduced in MacOS Mojave. Namely:

systemPreferences.getMediaAccessStatus(mediaType)
systemPreferences.askForMediaAccess(mediaType)

Apple Docs:

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines

Release Notes

Notes: Added media access APIs for macOS Mojave

@codebytere codebytere requested a review from a team November 7, 2018 17:39
@codebytere codebytere force-pushed the access-apis branch 2 times, most recently from ad39da6 to e2477bf Compare November 7, 2018 17:49
@codebytere codebytere changed the title feat: add media access apis for mojave [WIP] feat: add media access apis for mojave Nov 7, 2018
@codebytere codebytere requested a review from a team November 8, 2018 18:40
@codebytere codebytere changed the title [WIP] feat: add media access apis for mojave feat: add media access apis for mojave Nov 9, 2018
@alexeykuzmin alexeykuzmin added the semver/minor backwards-compatible functionality label Nov 12, 2018
@groundwater
Copy link
Contributor

We're 👍 on porting to 4.x post-merge if:

  • works with MAS
  • Works on older macos versions

However, there is still outstanding debate on the actual API cc @nornagon @codebytere

Copy link
Contributor

@miniak miniak left a comment

Choose a reason for hiding this comment

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

We should return an enum, with all the 4 possible values as returned by the OS API. Being able to distinguish between denied and restricted is quite important to be able to show appropriate UI to the users of the apps.

Copy link
Contributor

@miniak miniak left a comment

Choose a reason for hiding this comment

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

Also I think the API should just be a thin wrapper over the OS APIs. I would definitely not show any message boxes, let the app decide how to present that to the user.

Something like this:

getMediaAccessStatus(mediaType: 'audio' | 'video'): 'not-determined' | 'allowed' | 'denied' | 'restricted'
requestMediaAccess(mediaType: 'audio' | 'video'): Promise<boolean>

@miniak
Copy link
Contributor

miniak commented Nov 14, 2018

If you insist on providing a conveniece API, I would expose both the raw API, which provides all the states and just add an additional method to do that, which can be inplemented in JS using the low level APIs. This way the C++ code can stay much simpler and without any business logic

atom/browser/api/atom_api_system_preferences_mac.mm Outdated Show resolved Hide resolved
docs/api/system-preferences.md Outdated Show resolved Hide resolved
docs/api/system-preferences.md Outdated Show resolved Hide resolved
docs/api/system-preferences.md Outdated Show resolved Hide resolved
@rspeyer
Copy link

rspeyer commented Nov 14, 2018

+1 on @miniak's feedback - I think this API should do less to transform the data and be treated as more of a passthrough of Apple's data

Copy link
Contributor

@alexeykuzmin alexeykuzmin left a comment

Choose a reason for hiding this comment

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

Questions are up there.

atom/browser/ui/cocoa/atom_access_controller.mm Outdated Show resolved Hide resolved
docs/api/system-preferences.md Show resolved Hide resolved
docs/api/system-preferences.md Outdated Show resolved Hide resolved
@codebytere
Copy link
Member Author

This should be ready for review again, i've addressed all the above comments and simplified the impl to remove opinionated behaviors 😀

@miniak
Copy link
Contributor

miniak commented Dec 3, 2018

@alexeykuzmin, @nornagon can you please check the refactored version?

Copy link
Contributor

@alexeykuzmin alexeykuzmin left a comment

Choose a reason for hiding this comment

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

👍

atom/browser/api/atom_api_system_preferences_mac.mm Outdated Show resolved Hide resolved
@miniak miniak force-pushed the access-apis branch 2 times, most recently from 2d5132e to 2bc5505 Compare December 4, 2018 09:56
@miniak
Copy link
Contributor

miniak commented Dec 4, 2018

Verified to work properly on macOS 10.13
screen shot 2018-12-04 at 11 19 54 am
cc @groundwater

@miniak
Copy link
Contributor

miniak commented Dec 4, 2018

@rspeyer can you sign-off as well?

@codebytere codebytere merged commit c31629a into master Dec 4, 2018
@release-clerk
Copy link

release-clerk bot commented Dec 4, 2018

Release Notes Persisted

Added media access APIs for macOS Mojave

@trop
Copy link
Contributor

trop bot commented Dec 4, 2018

I have automatically backported this PR to "4-0-x", please check out #15948

@james-pellow
Copy link

I believe we still need to make default additions to the Electron.app/Contents/Info.plist file. Using this API in development is challenging given that NSMicrophoneUsageDescription and/or NSCameraUsageDescription are required by osx for the [AVCaptureDevice requestAccessForMediaType:type] call to succeed. Otherwise the app just crashes. I've temporarily solved this in my app by manually adding the keys to Electron.app/Contents/Info.plist in node_modules, then I call open ./node_modules/electron/dist/Electron.app -n -W --args $(pwd) to launch the app. This all still feels messy, and I doubt its what most uses are going to want to have to deal with. At least adding the default keys to Info.plist would help. Thoughts?

@nornagon
Copy link
Member

nornagon commented Jan 2, 2019

Perhaps we can add some default generic strings to Info.plist? That's how chrome does it (2).

@codebytere
Copy link
Member Author

good plan, i'll look into doing that today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet