pear-electron 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot.js +10 -5
- package/package.json +1 -1
- package/preload.js +11 -11
- package/runtime.js +2 -2
package/boot.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/** @typedef {import('pear-interface')} */
|
|
2
2
|
'use strict'
|
|
3
|
-
const
|
|
3
|
+
const { isElectron, isElectronRenderer, isElectronWorker, isWindows } = require('which-runtime')
|
|
4
|
+
const BOOT_ELECTRON_MAIN = 1
|
|
5
|
+
const BOOT_ELECTRON_PRELOAD = 2
|
|
6
|
+
const rtix = process.argv.indexOf('--runtime-info')
|
|
7
|
+
const rti = rtix > -1 && process.argv[rtix + 1]
|
|
8
|
+
const state = rti ? null : JSON.parse(process.argv.slice(isWindows ? -2 : -1)[0])
|
|
9
|
+
const RUNTIME_INFO = rti ? JSON.parse(rti) : state.runtimeInfo
|
|
10
|
+
|
|
4
11
|
class API {
|
|
5
12
|
static CHECKOUT = RUNTIME_INFO.checkout
|
|
6
13
|
static MOUNT = RUNTIME_INFO.mount
|
|
@@ -8,16 +15,14 @@ class API {
|
|
|
8
15
|
config = {}
|
|
9
16
|
}
|
|
10
17
|
global.Pear = new API()
|
|
11
|
-
|
|
12
|
-
const BOOT_ELECTRON_MAIN = 1
|
|
13
|
-
const BOOT_ELECTRON_PRELOAD = 2
|
|
18
|
+
|
|
14
19
|
switch (getBootType()) {
|
|
15
20
|
case BOOT_ELECTRON_MAIN: {
|
|
16
21
|
require('./electron-main.js')
|
|
17
22
|
break
|
|
18
23
|
}
|
|
19
24
|
case BOOT_ELECTRON_PRELOAD: {
|
|
20
|
-
require('./preload.js')
|
|
25
|
+
require('./preload.js')(state)
|
|
21
26
|
break
|
|
22
27
|
}
|
|
23
28
|
}
|
package/package.json
CHANGED
package/preload.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
/* global Pear */
|
|
4
4
|
/* eslint-env node, browser */
|
|
5
|
-
|
|
5
|
+
module.exports = (state) => {
|
|
6
|
+
if (!process.isMainFrame) return
|
|
6
7
|
const electron = require('electron')
|
|
7
8
|
const timers = require('timers')
|
|
8
9
|
const { isMac, isWindows, platform } = require('which-runtime')
|
|
9
10
|
const API = require('pear-api')
|
|
10
11
|
const GUI = require('./gui')
|
|
11
|
-
const
|
|
12
|
-
const { parentWcId, env, id, ...config } = state
|
|
12
|
+
const { parentWcId, env, id, runtimeInfo, ...config } = state
|
|
13
13
|
const isDecal = state.isDecal || false
|
|
14
14
|
if (config.key?.type === 'Buffer') config.key = Buffer.from(config.key.data)
|
|
15
15
|
const dir = config.dir
|
|
@@ -55,8 +55,8 @@ if (process.isMainFrame) {
|
|
|
55
55
|
warn.call(console, msg, ...args)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
if (
|
|
59
|
-
gui.ipc.get(
|
|
58
|
+
if (runtimeInfo.preload) {
|
|
59
|
+
gui.ipc.get(runtimeInfo.preload).then((preload) => {
|
|
60
60
|
eval(preload) // eslint-disable-line
|
|
61
61
|
}, console.error).finally(descopeGlobals)
|
|
62
62
|
} else {
|
|
@@ -302,12 +302,12 @@ if (process.isMainFrame) {
|
|
|
302
302
|
svg {
|
|
303
303
|
width: 1em;
|
|
304
304
|
height: 1em;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
305
|
+
}
|
|
306
|
+
#titlebar{
|
|
307
|
+
-webkit-app-region: drag;
|
|
308
|
+
width: 100%;
|
|
309
|
+
height: 50px;
|
|
310
|
+
}
|
|
311
311
|
</style>
|
|
312
312
|
<div id="titlebar">
|
|
313
313
|
<div id="ctrl">
|
package/runtime.js
CHANGED
|
@@ -70,9 +70,9 @@ class PearElectron {
|
|
|
70
70
|
const info = JSON.stringify({
|
|
71
71
|
checkout: constants.CHECKOUT,
|
|
72
72
|
mount: constants.MOUNT,
|
|
73
|
-
bridge: opts.bridge?.addr ?? undefined
|
|
73
|
+
bridge: opts.bridge?.addr ?? undefined
|
|
74
74
|
})
|
|
75
|
-
argv = [BOOT, '--runtime-info', info,
|
|
75
|
+
argv = [BOOT, '--runtime-info', info, ...argv]
|
|
76
76
|
const stdio = args.detach ? 'ignore' : ['ignore', 'inherit', 'pipe', 'pipe']
|
|
77
77
|
const sp = spawn(this.bin, argv, {
|
|
78
78
|
stdio,
|