-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathboot.js
More file actions
36 lines (33 loc) · 954 Bytes
/
boot.js
File metadata and controls
36 lines (33 loc) · 954 Bytes
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
'use strict'
const { isElectron, isElectronRenderer, isElectronWorker } = require('which-runtime')
const rtiFlagIx = process.argv.indexOf('--rti')
const RTI = rtiFlagIx > -1 && process.argv[rtiFlagIx + 1]
const match = process.argv.find((s) => s.startsWith('--state='))
const state = RTI ? null : JSON.parse(match.replace('--state=', ''))
const app = {}
class API {
static RTI = RTI ? JSON.parse(RTI) : state.rti // runtime information
static get CONSTANTS() {
return require('pear-constants')
}
app = app
config = app
}
global.Pear = new API()
const BOOT_ELECTRON_MAIN = 1
const BOOT_ELECTRON_PRELOAD = 2
switch (getBootType()) {
case BOOT_ELECTRON_MAIN: {
require('./electron-main.js')
break
}
case BOOT_ELECTRON_PRELOAD: {
require('./preload.js')(state)
break
}
}
function getBootType() {
if (isElectron) {
return isElectronRenderer || isElectronWorker ? BOOT_ELECTRON_PRELOAD : BOOT_ELECTRON_MAIN
}
}