-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
47 lines (36 loc) · 1.49 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
const proc = require('child_process')
const electron = require('./electron/main/node_modules/electron')
console.log("path to electron: " + electron)
console.log("dirname: " + __dirname)
/*
It is CRITICAL that you run electron with the --enable-sandbox on the MAIN process.
If you do not do this, then the OS-enforced sandbox is NOT ENABLED.
Your code will not be sandboxed without this flag.
Hence we spawn the process here.
*/
let child;
if (process.env.NODE_ENV === 'development') {
console.log('DEVELOPMENT mode\nproc.spawn should execute: ' + electron + __dirname + "/electron/main/dist/main.js");
child = proc.spawn(electron , [ __dirname + "/electron/main/dist/main.js"], {
env: Object.assign({ ELECTRON_ENV: 'development' }, process.env)
});
} else {
console.log('PRODUCTION mode\nproc.spawn should execute: ' + electron + '--enable-sandbox' + __dirname + "/electron/main/dist/main.js");
child = proc.spawn(electron , [/** "--enable-sandbox", */ __dirname + "/electron/main/dist/main.js"], {
env: Object.assign({ ELECTRON_ENV: 'production' }, process.env)
});
}
/* Catch the outputs of the electron child process */
child.stdout.on('data', (data) => {
console.log(`[electron] ${data}`);
});
child.stderr.on('data', (data) => {
console.log(`[electron] stderr: ${data}`);
});
child.on('close', (code) => {
console.log(`[electron] about to exit with code: ${code}`);
});
// on exit of this process
process.on('exit', (code) => {
console.log(`About to exit with code: ${code}`);
});