forked from sleeyax/pms-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
43 lines (37 loc) · 1.11 KB
/
main.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
// spawn processes in the same thread as the app
// (multiple child processes simply don't work here, so we have no choice but to use this)
process.env['NO_CHILDREN'] = '1'
const back = require('androidjs').back
const { init, getStatus } = require('./src/bootstrap');
const { writeToLog } = require('./src/helpers');
const timer = setInterval(() => {
const status = getStatus();
if (status.redirect) {
clearInterval(timer);
back.send('done', status.redirect)
} else if (status.msg) {
const splitted = status.msg.split('\n')
if (splitted.length == 2) {
back.send('log', status.msg + '<br><br><strong>' + splitted[1] + '</strong>', 'text-success', true)
} else {
back.send('log', status.msg)
}
} else {
back.send('log', 'status is null', 'text-danger')
}
}, 3000);
back.on('init', async () => {
// avoid duplicate app instances
const status = getStatus()
if (status.redirect) {
back.send('done', status.redirect)
return
}
// start PMS
try {
await init()
} catch (ex) {
back.send('log', 'Failed to load (' + ex + '). See logs for details!', 'text-danger', true)
}
})
back.on('log', writeToLog)