diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/electron/macOSPermissions.js | 86 | ||||
-rw-r--r-- | src/index.js | 3 |
2 files changed, 80 insertions, 9 deletions
diff --git a/src/electron/macOSPermissions.js b/src/electron/macOSPermissions.js index 4ba6a7619..682a46a41 100644 --- a/src/electron/macOSPermissions.js +++ b/src/electron/macOSPermissions.js | |||
@@ -1,14 +1,84 @@ | |||
1 | import { systemPreferences } from 'electron'; | 1 | import { app, systemPreferences, dialog } from 'electron'; |
2 | import { | 2 | import fs from 'fs'; |
3 | hasScreenCapturePermission, | 3 | import macosVersion from 'macos-version'; |
4 | hasPromptedForPermission, | 4 | import path from 'path'; |
5 | } from 'mac-screen-capture-permissions'; | 5 | import { isMac } from '../environment'; |
6 | 6 | ||
7 | export default function () { | 7 | let askForScreenCaptureAccess; |
8 | if (isMac) { | ||
9 | // eslint-disable-next-line global-require | ||
10 | askForScreenCaptureAccess = require('node-mac-permissions').askForScreenCaptureAccess; | ||
11 | } | ||
12 | |||
13 | const debug = require('debug')('Franz:macOSPermissions'); | ||
14 | |||
15 | const permissionExists = macosVersion.isGreaterThanOrEqualTo('10.15'); | ||
16 | const filePath = path.join(app.getPath('userData'), '.has-app-requested-screen-capture-permissions'); | ||
17 | |||
18 | function hasPromptedForPermission() { | ||
19 | if (!permissionExists) { | ||
20 | return false; | ||
21 | } | ||
22 | |||
23 | if (filePath && fs.existsSync(filePath)) { | ||
24 | return true; | ||
25 | } | ||
26 | |||
27 | return false; | ||
28 | } | ||
29 | |||
30 | function hasScreenCapturePermission() { | ||
31 | if (!permissionExists) { | ||
32 | return true; | ||
33 | } | ||
34 | |||
35 | const screenCaptureStatus = systemPreferences.getMediaAccessStatus('screen'); | ||
36 | return screenCaptureStatus === 'granted'; | ||
37 | } | ||
38 | |||
39 | function createStatusFile() { | ||
40 | try { | ||
41 | fs.writeFileSync(filePath, ''); | ||
42 | } catch (error) { | ||
43 | if (error.code === 'ENOENT') { | ||
44 | fs.mkdirSync(path.dirname(filePath)); | ||
45 | fs.writeFileSync(filePath, ''); | ||
46 | } | ||
47 | |||
48 | throw error; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | |||
53 | export default async function (mainWindow) { | ||
54 | debug('Checking camera & microphone permissions'); | ||
8 | systemPreferences.askForMediaAccess('camera'); | 55 | systemPreferences.askForMediaAccess('camera'); |
9 | systemPreferences.askForMediaAccess('microphone'); | 56 | systemPreferences.askForMediaAccess('microphone'); |
10 | 57 | ||
11 | if (!hasPromptedForPermission()) { | 58 | if (!hasPromptedForPermission() && !hasScreenCapturePermission()) { |
12 | hasScreenCapturePermission(); | 59 | debug('Checking screen capture permissions'); |
60 | |||
61 | const { response } = await dialog.showMessageBox(mainWindow, { | ||
62 | type: 'info', | ||
63 | message: 'Enable Screen Sharing', | ||
64 | detail: 'To enable screen sharing for some services, Franz needs the permission to record your screen.', | ||
65 | buttons: [ | ||
66 | 'Allow screen sharing', | ||
67 | 'No', | ||
68 | 'Ask me later', | ||
69 | ], | ||
70 | defaultId: 0, | ||
71 | cancelId: 2, | ||
72 | }); | ||
73 | |||
74 | console.log('result', response); | ||
75 | if (response === 0) { | ||
76 | debug('Asking for access'); | ||
77 | askForScreenCaptureAccess(); | ||
78 | createStatusFile(); | ||
79 | } else if (response === 1) { | ||
80 | debug('Don\'t ask again'); | ||
81 | createStatusFile(); | ||
82 | } | ||
13 | } | 83 | } |
14 | } | 84 | } |
diff --git a/src/index.js b/src/index.js index 2586ab401..d251af958 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -10,6 +10,7 @@ import fs from 'fs-extra'; | |||
10 | import path from 'path'; | 10 | import path from 'path'; |
11 | import windowStateKeeper from 'electron-window-state'; | 11 | import windowStateKeeper from 'electron-window-state'; |
12 | import { enforceMacOSAppLocation } from 'electron-util'; | 12 | import { enforceMacOSAppLocation } from 'electron-util'; |
13 | import ms from 'ms'; | ||
13 | 14 | ||
14 | // TODO: This seems to be duplicated between here and 'config.js' | 15 | // TODO: This seems to be duplicated between here and 'config.js' |
15 | // Set app directory before loading user modules | 16 | // Set app directory before loading user modules |
@@ -328,7 +329,7 @@ const createWindow = () => { | |||
328 | }); | 329 | }); |
329 | 330 | ||
330 | if (isMac) { | 331 | if (isMac) { |
331 | askFormacOSPermissions(); | 332 | setTimeout(() => askFormacOSPermissions(mainWindow), ms('30s')); |
332 | } | 333 | } |
333 | 334 | ||
334 | mainWindow.on('show', () => { | 335 | mainWindow.on('show', () => { |