This repository was archived by the owner on Apr 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
105 lines (93 loc) · 2.59 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
let autostart;
/* istanbul ignore next */
switch (process.platform) {
case 'darwin':
autostart = require('./lib/darwin.js');
break;
case 'linux':
autostart = require('./lib/linux.js');
break;
case 'win32':
autostart = require('./lib/win32.js');
break;
default:
autostart = null;
}
function enableAutostart(key, command, path, callback) {
if (arguments.length < 3) {
throw new Error('Not enough arguments passed to enableAutostart()');
} else if (typeof key !== 'string') {
throw new TypeError('Passed "key" to enableAutostart() is not a string.');
} else if (typeof command !== 'string') {
throw new TypeError('Passed "command" to enableAutostart() is not a string.');
} else if (typeof path !== 'string') {
throw new TypeError('Passed "path" to enableAutostart() is not a string.');
}
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.enableAutostart(key, command, path, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
return autostart.enableAutostart(key, command, path, error => {
callback(error);
});
}
function disableAutostart(key, callback) {
if (arguments.length < 1) {
throw new Error('Not enough arguments passed to disableAutostart()');
} else if (typeof key !== 'string') {
throw new TypeError('Passed "key" to disableAutostart() is not a string.');
}
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.disableAutostart(key, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
autostart.disableAutostart(key, error => {
callback(error);
});
}
/**
* Checks if autostart is enabled
* @param {String} key
* @param {Function} callback
*/
function isAutostartEnabled(key, callback) {
if (arguments.length < 1) {
throw new Error('Not enough arguments passed to isAutostartEnabled()');
} else if (typeof key !== 'string') {
throw new TypeError('Passed "key" to disableAutostart() is not a string.');
}
if (typeof callback !== 'function') {
return new Promise((resolve, reject) => {
autostart.isAutostartEnabled(key, (error, isEnabled) => {
if (error) {
reject(error);
} else {
resolve(isEnabled);
}
});
});
}
autostart.isAutostartEnabled(key, (error, isEnabled) => {
callback(error, isEnabled);
});
}
module.exports = {
enableAutostart,
disableAutostart,
isAutostartEnabled
};