-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (59 loc) · 1.47 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
// const awake = require('bindings')('awake');
let awake = {}
const os = require('os');
if (os.platform() == 'darwin') {
awake = require('./build/Release/awake.node')
} else {
module.exports = {
disableScreenSleep: (reason) => false,
enableScreenSleep: () => false,
}
return
}
let lockId = null;
const disableScreenSleep = (reason) => {
if (lockId == null) {
lockId = awake.disableScreenSleep(reason)
return lockId != null
} else {
return true
}
}
const enableScreenSleep = () => {
if (lockId == null) {
return true
} else {
let ok = awake.enableScreenSleep(lockId)
lockId = null
return ok
}
}
const openUrl = (url) => {
return awake.openUrl(url)
}
function cleanup(callback) {
// attach user callback to the process event emitter
// if no callback, it will still exit gracefully on Ctrl-C
callback = callback || noOp;
process.on('cleanup', callback);
// do app specific cleaning before exiting
process.on('exit', function () {
process.emit('cleanup');
});
// catch ctrl+c event and exit normally
process.on('SIGINT', function () {
process.exit(2);
});
//catch uncaught exceptions, trace, then exit normally
process.on('uncaughtException', function (e) {
process.exit(99);
});
};
cleanup(() => {
enableScreenSleep()
})
module.exports = {
disableScreenSleep,
enableScreenSleep,
openUrl,
}