-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.js
86 lines (71 loc) · 2.55 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const permissions = require('bindings')('permissions.node')
function getAuthStatus(type) {
const validTypes = [
'accessibility',
'bluetooth',
'calendar',
'camera',
'contacts',
'full-disk-access',
'input-monitoring',
'location',
'microphone',
'music-library',
'photos-add-only',
'photos-read-write',
'reminders',
'speech-recognition',
'screen',
]
if (!validTypes.includes(type)) {
throw new TypeError(`${type} is not a valid type`)
}
return permissions.getAuthStatus.call(this, type)
}
function askForFoldersAccess(folder) {
const validFolders = ['desktop', 'documents', 'downloads']
if (!validFolders.includes(folder)) {
throw new TypeError(`${folder} is not a valid protected folder`)
}
return permissions.askForFoldersAccess.call(this, folder)
}
function askForCalendarAccess(accessLevel = 'write-only') {
if (!['write-only', 'full'].includes(accessLevel)) {
throw new TypeError(`${accessLevel} must be one of either 'write-only' or 'full'`)
}
return permissions.askForCalendarAccess.call(this, accessLevel)
}
function askForScreenCaptureAccess(openPreferences = false) {
if (typeof openPreferences !== 'boolean') {
throw new TypeError('openPreferences must be a boolean')
}
return permissions.askForScreenCaptureAccess.call(this, openPreferences)
}
function askForPhotosAccess(accessLevel = 'add-only') {
if (!['add-only', 'read-write'].includes(accessLevel)) {
throw new TypeError(`${accessLevel} must be one of either 'add-only' or 'read-write'`)
}
return permissions.askForPhotosAccess.call(this, accessLevel)
}
function askForInputMonitoringAccess(accessLevel = 'listen') {
if (!['listen', 'post'].includes(accessLevel)) {
throw new TypeError(`${accessLevel} must be one of either 'listen' or 'post'`)
}
return permissions.askForInputMonitoringAccess.call(this, accessLevel)
}
module.exports = {
askForAccessibilityAccess: permissions.askForAccessibilityAccess,
askForCalendarAccess: askForCalendarAccess,
askForCameraAccess: permissions.askForCameraAccess,
askForContactsAccess: permissions.askForContactsAccess,
askForFoldersAccess,
askForFullDiskAccess: permissions.askForFullDiskAccess,
askForInputMonitoringAccess,
askForRemindersAccess: permissions.askForRemindersAccess,
askForMicrophoneAccess: permissions.askForMicrophoneAccess,
askForMusicLibraryAccess: permissions.askForMusicLibraryAccess,
askForPhotosAccess,
askForSpeechRecognitionAccess: permissions.askForSpeechRecognitionAccess,
askForScreenCaptureAccess,
getAuthStatus,
}