forked from signalapp/Signal-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.js
64 lines (54 loc) · 1.96 KB
/
permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// The list of permissions is here:
// https://electronjs.org/docs/api/session#sessetpermissionrequesthandlerhandler
const PERMISSIONS = {
// Allowed
fullscreen: true, // required to show videos in full-screen
notifications: true, // required to show OS notifications for new messages
// Off by default, can be enabled by user
media: false, // required for access to microphone and camera, used for voice notes and calling
// Not allowed
geolocation: false,
midiSysex: false,
openExternal: false, // we don't need this; we open links via 'will-navigate' event
pointerLock: false,
};
function _createPermissionHandler(userConfig) {
return (webContents, permission, callback, details) => {
// We default 'media' permission to false, but the user can override that for
// the microphone and camera.
if (
permission === 'media' &&
details.mediaTypes.includes('audio') &&
userConfig.get('mediaPermissions')
) {
return callback(true);
}
if (
permission === 'media' &&
details.mediaTypes.includes('video') &&
userConfig.get('mediaCameraPermissions')
) {
return callback(true);
}
if (PERMISSIONS[permission]) {
console.log(`Approving request for permission '${permission}'`);
return callback(true);
}
console.log(`Denying request for permission '${permission}'`);
return callback(false);
};
}
function installPermissionsHandler({ session, userConfig }) {
// Setting the permission request handler to null first forces any permissions to be
// requested again. Without this, revoked permissions might still be available if
// they've already been used successfully.
session.defaultSession.setPermissionRequestHandler(null);
session.defaultSession.setPermissionRequestHandler(
_createPermissionHandler(userConfig)
);
}
module.exports = {
installPermissionsHandler,
};