forked from HaikuTeam/animator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (61 loc) · 2.12 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
const path = require('path');
const cp = require('child_process');
const os = require('os');
if (!global.process.env.NODE_ENV || global.process.env.NODE_ENV === 'production') {
process.env.HAIKU_GLASS_URL_MODE = 'distro';
process.env.HAIKU_TIMELINE_URL_MODE = 'distro';
process.env.HAIKU_INTERPRETER_URL_MODE = 'distro';
if (process.env.HAIKU_APP_LAUNCH_CLI === '1') {
process.env.HAIKU_APP_SKIP_LOG = '1';
}
require('./config');
}
// On Windows and Linux, custom protocol handler is passed as argument
const haikuURI = process.argv.find((arg) => arg.startsWith('haiku://'));
if (process.env.HAIKU_APP_LAUNCH_CLI === '1') {
require('@haiku/cli');
} else {
const {app, dialog} = require('electron');
if (process.env.NODE_ENV === 'production' && os.platform() === 'darwin' && !app.isInApplicationsFolder()) {
dialog.showErrorBox(
'Move to Applications folder',
'You cannot run Animator from the current folder. Please move Animator to the Applications folder and try again.',
);
global.process.exit(0);
}
app.once('open-url', (event, url) => {
global.process.env.HAIKU_INITIAL_URL = url;
});
if (haikuURI) {
global.process.env.HAIKU_INITIAL_URL = haikuURI;
}
const haikuHelperArgs = {stdio: 'inherit'};
if (global.process.env.HAIKU_DEBUG) {
haikuHelperArgs.execArgv = ['--inspect=9221'];
}
global.haikuHelper = cp.fork(path.join(__dirname, 'HaikuHelper'), haikuHelperArgs);
global.haikuHelper.on('message', (data) => {
if (!data || typeof data !== 'object' || !data.message) {
return;
}
const {message} = data;
switch (message) {
case 'launchCreator':
global.process.env.HAIKU_ENV = JSON.stringify(data.haiku);
require('haiku-creator/lib/electron');
break;
case 'bakePngSequence':
require('haiku-creator/lib/bakery/electron').default(
data,
() => {
global.haikuHelper.send({type: 'bakePngSequenceComplete'});
},
);
break;
}
});
global.haikuHelper.on('exit', global.process.exit);
global.process.on('exit', () => {
haikuHelper.kill('SIGKILL');
});
}