Skip to content

Commit 1a23d4b

Browse files
authored
fix: Media permissions (#1740)
* Ask for media access on MacOS * Update Snap plugs
1 parent c30866d commit 1a23d4b

2 files changed

Lines changed: 58 additions & 27 deletions

File tree

electron-builder.json

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"NSMicrophoneUsageDescription": "I need access to your microphone to record the audio you want to send.",
2727
"NSCameraUsageDescription": "I need access to your camera to record the video you want to send."
2828
},
29-
"hardenedRuntime" : true,
29+
"hardenedRuntime": true,
3030
"gatekeeperAssess": false,
3131
"provisioningProfile": "embedded.provisionprofile"
3232
},
@@ -53,7 +53,7 @@
5353
"mas": {
5454
"entitlements": "build/entitlements.mas.plist",
5555
"entitlementsInherit": "build/entitlements.mas.inherit.plist",
56-
"hardenedRuntime" : true,
56+
"hardenedRuntime": true,
5757
"asarUnpack": [
5858
"node_modules"
5959
],
@@ -66,33 +66,33 @@
6666
],
6767
"icon": "build/icon.ico",
6868
"publisherName": "Sectigo RSA Code Signing CA",
69-
"legalTrademarks": "",
70-
"verifyUpdateCodeSignature": true,
71-
"requestedExecutionLevel": "asInvoker",
72-
"signAndEditExecutable": true,
73-
"signDlls": false
69+
"legalTrademarks": "",
70+
"verifyUpdateCodeSignature": true,
71+
"requestedExecutionLevel": "asInvoker",
72+
"signAndEditExecutable": true,
73+
"signDlls": false
7474
},
7575
"nsis": {
7676
"oneClick": false,
7777
"perMachine": false,
7878
"allowElevation": true,
7979
"allowToChangeInstallationDirectory": true,
8080
"installerIcon": "build/installerIcon.ico",
81-
"uninstallerIcon": "build/uninstallerIcon.ico",
82-
"installerSidebar": "build/installerSidebar.bmp",
83-
"uninstallerSidebar": "build/uninstallerSidebar.bmp",
84-
"uninstallDisplayName": "${productName} ${version}",
85-
"include": "build/installer.nsh",
86-
"license": "LICENSE",
87-
"artifactName": "rocketchat-setup-${version}.${ext}",
88-
"deleteAppDataOnUninstall": false,
89-
"displayLanguageSelector": false,
90-
"unicode": true,
91-
"warningsAsErrors": true,
92-
"runAfterFinish": true,
93-
"createDesktopShortcut": "always",
94-
"createStartMenuShortcut": true,
95-
"menuCategory": false
81+
"uninstallerIcon": "build/uninstallerIcon.ico",
82+
"installerSidebar": "build/installerSidebar.bmp",
83+
"uninstallerSidebar": "build/uninstallerSidebar.bmp",
84+
"uninstallDisplayName": "${productName} ${version}",
85+
"include": "build/installer.nsh",
86+
"license": "LICENSE",
87+
"artifactName": "rocketchat-setup-${version}.${ext}",
88+
"deleteAppDataOnUninstall": false,
89+
"displayLanguageSelector": false,
90+
"unicode": true,
91+
"warningsAsErrors": true,
92+
"runAfterFinish": true,
93+
"createDesktopShortcut": "always",
94+
"createStartMenuShortcut": true,
95+
"menuCategory": false
9696
},
9797
"msi": {
9898
"artifactName": "rocketchat-setup-${version}.${ext}"
@@ -131,7 +131,23 @@
131131
},
132132
"snap": {
133133
"artifactName": "rocketchat_${version}_${arch}.${ext}",
134-
"plugs": ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl", "camera"]
134+
"plugs": [
135+
"desktop",
136+
"desktop-legacy",
137+
"home",
138+
"x11",
139+
"unity7",
140+
"browser-support",
141+
"network",
142+
"gsettings",
143+
"pulseaudio",
144+
"opengl",
145+
"camera",
146+
"audio-playback",
147+
"audio-record",
148+
"screen-inhibit-control",
149+
"upower-observe"
150+
]
135151
},
136152
"afterSign": "./build/notarize.js",
137153
"publish": [

src/ui/main/webviews.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Session,
1616
session,
1717
shell,
18+
systemPreferences,
1819
UploadBlob,
1920
UploadFile,
2021
UploadRawData,
@@ -427,9 +428,21 @@ export const attachGuestWebContentsEvents = (rootWindow: BrowserWindow): void =>
427428
});
428429

429430
const webviewsSession = session.fromPartition('persist:rocketchat-server');
430-
webviewsSession.setPermissionRequestHandler((_webContents, permission, callback, details) => {
431+
webviewsSession.setPermissionRequestHandler(async (_webContents, permission, callback, details) => {
431432
switch (permission) {
432-
case 'media':
433+
case 'media': {
434+
if (process.platform !== 'darwin') {
435+
callback(true);
436+
return;
437+
}
438+
439+
const { mediaTypes } = details;
440+
const allowed = (!mediaTypes.includes('audio') || await systemPreferences.askForMediaAccess('microphone'))
441+
&& (!mediaTypes.includes('video') || await systemPreferences.askForMediaAccess('camera'));
442+
callback(allowed);
443+
return;
444+
}
445+
433446
case 'geolocation':
434447
case 'notifications':
435448
case 'midiSysex':
@@ -438,9 +451,11 @@ export const attachGuestWebContentsEvents = (rootWindow: BrowserWindow): void =>
438451
callback(true);
439452
return;
440453

441-
case 'openExternal':
442-
isProtocolAllowed(details.externalURL).then(callback);
454+
case 'openExternal': {
455+
const allowed = await isProtocolAllowed(details.externalURL);
456+
callback(allowed);
443457
return;
458+
}
444459

445460
default:
446461
callback(false);

0 commit comments

Comments
 (0)