aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/macOSPermissions.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/electron/macOSPermissions.js')
-rw-r--r--src/electron/macOSPermissions.js67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/electron/macOSPermissions.js b/src/electron/macOSPermissions.js
index 940b16c6e..887af2903 100644
--- a/src/electron/macOSPermissions.js
+++ b/src/electron/macOSPermissions.js
@@ -1,83 +1,80 @@
1import { app, systemPreferences, dialog } from 'electron'; 1import { systemPreferences, dialog } from 'electron';
2import fs from 'fs'; 2import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra';
3import macosVersion from 'macos-version'; 3import macosVersion from 'macos-version';
4import path from 'path'; 4import { dirname } from 'path';
5import { isMac } from '../environment'; 5import { askForScreenCaptureAccess } from 'node-mac-permissions';
6 6import { userDataPath } from '../environment';
7let askForScreenCaptureAccess;
8if (isMac) {
9 // eslint-disable-next-line global-require
10 askForScreenCaptureAccess = require('node-mac-permissions').askForScreenCaptureAccess;
11}
12 7
13const debug = require('debug')('Ferdi:macOSPermissions'); 8const debug = require('debug')('Ferdi:macOSPermissions');
14 9
15const permissionExists = macosVersion.isGreaterThanOrEqualTo('10.15'); 10const isExplicitScreenCapturePermissionReqd = macosVersion.isGreaterThanOrEqualTo('10.15');
16const filePath = path.join(app.getPath('userData'), '.has-app-requested-screen-capture-permissions'); 11debug(`Should check explicitly for screen-capture permissions: ${isExplicitScreenCapturePermissionReqd}`);
17 12
18function hasPromptedForPermission() { 13const filePath = userDataPath('.has-app-requested-screen-capture-permissions');
19 if (!permissionExists) {
20 return false;
21 }
22 14
23 if (filePath && fs.existsSync(filePath)) { 15function hasPromptedForScreenCapturePermission() {
24 return true; 16 if (!isExplicitScreenCapturePermissionReqd) {
17 return false;
25 } 18 }
26 19
27 return false; 20 debug('Checking if status file exists');
21 return filePath && pathExistsSync(filePath);
28} 22}
29 23
30function hasScreenCapturePermission() { 24function hasScreenCapturePermissionAlreadyBeenGranted() {
31 if (!permissionExists) { 25 if (!isExplicitScreenCapturePermissionReqd) {
32 return true; 26 return true;
33 } 27 }
34 28
35 const screenCaptureStatus = systemPreferences.getMediaAccessStatus('screen'); 29 const screenCaptureStatus = systemPreferences.getMediaAccessStatus('screen');
30 debug(`screen-capture permissions status: ${screenCaptureStatus}`);
36 return screenCaptureStatus === 'granted'; 31 return screenCaptureStatus === 'granted';
37} 32}
38 33
39function createStatusFile() { 34function createStatusFile() {
40 try { 35 try {
41 fs.writeFileSync(filePath, ''); 36 writeFileSync(filePath, '');
42 } catch (error) { 37 } catch (error) {
43 if (error.code === 'ENOENT') { 38 if (error.code === 'ENOENT') {
44 fs.mkdirSync(path.dirname(filePath)); 39 mkdirSync(dirname(filePath));
45 fs.writeFileSync(filePath, ''); 40 writeFileSync(filePath, '');
46 } 41 }
47 42
48 throw error; 43 throw error;
49 } 44 }
50} 45}
51 46
52export default async function (mainWindow) { 47export const askFormacOSPermissions = async mainWindow => {
53 debug('Checking camera & microphone permissions'); 48 debug('Checking camera & microphone permissions');
54 systemPreferences.askForMediaAccess('camera'); 49 systemPreferences.askForMediaAccess('camera');
55 systemPreferences.askForMediaAccess('microphone'); 50 systemPreferences.askForMediaAccess('microphone');
56 51
57 if (!hasPromptedForPermission() && !hasScreenCapturePermission()) { 52 if (hasScreenCapturePermissionAlreadyBeenGranted()) {
53 debug('Already obtained screen-capture permissions - writing status file');
54 createStatusFile();
55 return;
56 }
57
58 if (!hasPromptedForScreenCapturePermission()) {
58 debug('Checking screen capture permissions'); 59 debug('Checking screen capture permissions');
59 60
60 const { response } = await dialog.showMessageBox(mainWindow, { 61 const { response } = await dialog.showMessageBox(mainWindow, {
61 type: 'info', 62 type: 'info',
62 message: 'Enable Screen Sharing', 63 message: 'Enable Screen Sharing',
63 detail: 'To enable screen sharing for some services, Ferdi needs the permission to record your screen.', 64 detail:
64 buttons: [ 65 'To enable screen sharing for some services, Ferdi needs the permission to record your screen.',
65 'Allow screen sharing', 66 buttons: ['Allow screen sharing', 'No', 'Ask me later'],
66 'No',
67 'Ask me later',
68 ],
69 defaultId: 0, 67 defaultId: 0,
70 cancelId: 2, 68 cancelId: 2,
71 }); 69 });
72 70
73 console.log('result', response);
74 if (response === 0) { 71 if (response === 0) {
75 debug('Asking for access'); 72 debug('Asking for access');
76 askForScreenCaptureAccess(); 73 askForScreenCaptureAccess();
77 createStatusFile(); 74 createStatusFile();
78 } else if (response === 1) { 75 } else if (response === 1) {
79 debug('Don\'t ask again'); 76 debug("Don't ask again");
80 createStatusFile(); 77 createStatusFile();
81 } 78 }
82 } 79 }
83} 80};