From 7947cc20ddbfe9e87fd77555ea6f6ae4922219af Mon Sep 17 00:00:00 2001 From: Vulich Fernando <46904390+fvulich@users.noreply.github.com> Date: Fri, 14 Feb 2020 17:35:31 -0300 Subject: [PATCH] Grant camera/microphone permission to macOS Catalina --- app.js | 4 ++++ app/Application.js | 43 ++++++++++++++++++++++++++++++++++++++++++ electron/menu.js | 15 ++++++++++++++- entitlements.mac.plist | 14 ++++++++++++++ package.json | 8 +++++++- 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 entitlements.mac.plist diff --git a/app.js b/app.js index 0540da48..c7a3f9cb 100644 --- a/app.js +++ b/app.js @@ -28,6 +28,10 @@ ipc.on('showAbout', function(event, message) { ipc.on('showPreferences', function(event, message) { !Ext.cq1('preferences') ? Ext.create('Rambox.view.preferences.Preferences').show() : ''; }); +ipc.on('grantPermissions', async function() { + await require('electron').remote.systemPreferences.askForMediaAccess('microphone'); + await require('electron').remote.systemPreferences.askForMediaAccess('camera'); +}); ipc.on('autoUpdater:check-update', function() { Rambox.app.checkUpdate(); }); diff --git a/app/Application.js b/app/Application.js index 830a12b3..63b2ec06 100644 --- a/app/Application.js +++ b/app/Application.js @@ -60,6 +60,49 @@ Ext.define('Rambox.Application', { }) })(); + if ( !localStorage.getItem('hideMacPermissions') && process.platform === 'darwin' && (require('electron').remote.systemPreferences.getMediaAccessStatus('microphone') !== 'granted' || require('electron').remote.systemPreferences.getMediaAccessStatus('camera') !== 'granted') ) { + console.info('Checking mac permissions...'); + Ext.cq1('app-main').addDocked({ + xtype: 'toolbar' + ,dock: 'top' + ,style: {background: '#30BBF3'} + ,items: [ + '->' + ,{ + xtype: 'label' + ,html: 'Rambox Pro needs permissions to use Microphone and Camera for the apps.' + } + ,{ + xtype: 'button' + ,text: 'Grant permissions' + ,ui: 'decline' + ,handler: async function(btn) { + await require('electron').remote.systemPreferences.askForMediaAccess('microphone'); + await require('electron').remote.systemPreferences.askForMediaAccess('camera'); + Ext.cq1('app-main').removeDocked(btn.up('toolbar'), true); + } + } + ,{ + xtype: 'button' + ,text: 'Never ask again' + ,ui: 'decline' + ,handler: function(btn) { + Ext.cq1('app-main').removeDocked(btn.up('toolbar'), true); + localStorage.setItem('hideMacPermissions', true); + } + } + ,'->' + ,{ + glyph: 'xf00d@FontAwesome' + ,baseCls: '' + ,style: 'cursor:pointer;' + ,handler: function(btn) { Ext.cq1('app-main').removeDocked(btn.up('toolbar'), true); } + } + ] + }); + } + + Ext.getStore('ServicesList').load(function (records, operations, success) { if (!success) { diff --git a/electron/menu.js b/electron/menu.js index 4a5729a4..a49c9882 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -1,6 +1,7 @@ 'use strict'; const os = require('os'); const electron = require('electron'); +const { systemPreferences } = require('electron') const app = electron.app; const BrowserWindow = electron.BrowserWindow; const shell = electron.shell; @@ -229,7 +230,7 @@ module.exports = function(config) { } ]; - if (process.platform === 'darwin') { + if ( process.platform === 'darwin' ) { tpl.unshift({ label: appName, submenu: [ @@ -288,6 +289,18 @@ module.exports = function(config) { } ] }); + helpSubmenu.push({ + type: 'separator' + }); + helpSubmenu.push({ + label: 'Grant Microphone and Camera permissions', + visible: systemPreferences.getMediaAccessStatus('microphone') !== 'granted' || systemPreferences.getMediaAccessStatus('camera') !== 'granted', + click(item, win) { + const webContents = win.webContents; + const send = webContents.send.bind(win.webContents); + send('grantPermissions'); + } + }); } else { tpl.unshift({ label: '&'+locale['menu.file[0]'], diff --git a/entitlements.mac.plist b/entitlements.mac.plist new file mode 100644 index 00000000..7d10056a --- /dev/null +++ b/entitlements.mac.plist @@ -0,0 +1,14 @@ + + + + + com.apple.security.cs.allow-unsigned-executable-memory + + com.apple.security.device.microphone + + com.apple.security.device.camera + + com.apple.security.device.audio-input + + + diff --git a/package.json b/package.json index 830a0ab3..2f70d65a 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,13 @@ "artifactName": "Rambox-${version}-mac.${ext}", "target": [ "default" - ] + ], + "entitlements": "entitlements.mac.plist", + "entitlementsInherit": "entitlements.mac.plist", + "extendInfo": { + "NSMicrophoneUsageDescription": "Apps inside Rambox may need access to your microphone. Please, grant access to have a better experience.", + "NSCameraUsageDescription": "Apps inside Rambox may need access to your camera. Please, grant access to have a better experience." + } }, "dmg": { "title": "Rambox",