diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 11:03:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 11:03:28 +0200 |
commit | 087113d8a1214ba4c7df03bfe66747d8d944280c (patch) | |
tree | 4d853a03057138dfa845cd6a7d91ccf63565a1a6 /src/electron/macOSPermissions.js | |
parent | chore: codebase improvements (#1930) (diff) | |
download | ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.gz ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.zst ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.zip |
chore: convert JS to TS (#1934)
Diffstat (limited to 'src/electron/macOSPermissions.js')
-rw-r--r-- | src/electron/macOSPermissions.js | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/src/electron/macOSPermissions.js b/src/electron/macOSPermissions.js deleted file mode 100644 index 887af2903..000000000 --- a/src/electron/macOSPermissions.js +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | import { systemPreferences, dialog } from 'electron'; | ||
2 | import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra'; | ||
3 | import macosVersion from 'macos-version'; | ||
4 | import { dirname } from 'path'; | ||
5 | import { askForScreenCaptureAccess } from 'node-mac-permissions'; | ||
6 | import { userDataPath } from '../environment'; | ||
7 | |||
8 | const debug = require('debug')('Ferdi:macOSPermissions'); | ||
9 | |||
10 | const isExplicitScreenCapturePermissionReqd = macosVersion.isGreaterThanOrEqualTo('10.15'); | ||
11 | debug(`Should check explicitly for screen-capture permissions: ${isExplicitScreenCapturePermissionReqd}`); | ||
12 | |||
13 | const filePath = userDataPath('.has-app-requested-screen-capture-permissions'); | ||
14 | |||
15 | function hasPromptedForScreenCapturePermission() { | ||
16 | if (!isExplicitScreenCapturePermissionReqd) { | ||
17 | return false; | ||
18 | } | ||
19 | |||
20 | debug('Checking if status file exists'); | ||
21 | return filePath && pathExistsSync(filePath); | ||
22 | } | ||
23 | |||
24 | function hasScreenCapturePermissionAlreadyBeenGranted() { | ||
25 | if (!isExplicitScreenCapturePermissionReqd) { | ||
26 | return true; | ||
27 | } | ||
28 | |||
29 | const screenCaptureStatus = systemPreferences.getMediaAccessStatus('screen'); | ||
30 | debug(`screen-capture permissions status: ${screenCaptureStatus}`); | ||
31 | return screenCaptureStatus === 'granted'; | ||
32 | } | ||
33 | |||
34 | function createStatusFile() { | ||
35 | try { | ||
36 | writeFileSync(filePath, ''); | ||
37 | } catch (error) { | ||
38 | if (error.code === 'ENOENT') { | ||
39 | mkdirSync(dirname(filePath)); | ||
40 | writeFileSync(filePath, ''); | ||
41 | } | ||
42 | |||
43 | throw error; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | export const askFormacOSPermissions = async mainWindow => { | ||
48 | debug('Checking camera & microphone permissions'); | ||
49 | systemPreferences.askForMediaAccess('camera'); | ||
50 | systemPreferences.askForMediaAccess('microphone'); | ||
51 | |||
52 | if (hasScreenCapturePermissionAlreadyBeenGranted()) { | ||
53 | debug('Already obtained screen-capture permissions - writing status file'); | ||
54 | createStatusFile(); | ||
55 | return; | ||
56 | } | ||
57 | |||
58 | if (!hasPromptedForScreenCapturePermission()) { | ||
59 | debug('Checking screen capture permissions'); | ||
60 | |||
61 | const { response } = await dialog.showMessageBox(mainWindow, { | ||
62 | type: 'info', | ||
63 | message: 'Enable Screen Sharing', | ||
64 | detail: | ||
65 | 'To enable screen sharing for some services, Ferdi needs the permission to record your screen.', | ||
66 | buttons: ['Allow screen sharing', 'No', 'Ask me later'], | ||
67 | defaultId: 0, | ||
68 | cancelId: 2, | ||
69 | }); | ||
70 | |||
71 | if (response === 0) { | ||
72 | debug('Asking for access'); | ||
73 | askForScreenCaptureAccess(); | ||
74 | createStatusFile(); | ||
75 | } else if (response === 1) { | ||
76 | debug("Don't ask again"); | ||
77 | createStatusFile(); | ||
78 | } | ||
79 | } | ||
80 | }; | ||