'How to trigger the camera/microphone permissions dialog box in macOS using electron

Background:

I building the electron app which has a permissions page - where I am checking for camera/microphone permission. If permissions are not granted then ask for it.

Codebase on click:

if (systemPreferences.getMediaAccessStatus('camera') !== 'granted') {
    await systemPreferences.askForMediaAccess('camera').then(result => {
        return result;
    });
} else {
    return true;
}

Looking for:

on button click if permissions not there should open mac camera permissions - which is not doing its job from above.

Note: macOS version: 12.0.1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source