pear-electron 0.0.4 → 0.1.1
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/gui/gui.js +5 -4
- package/package.json +1 -1
- package/preload.js +11 -11
- package/runtime.js +1 -1
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/gui/gui.js
CHANGED
|
@@ -806,7 +806,8 @@ class GuiCtrl {
|
|
|
806
806
|
this.parentId = parentId
|
|
807
807
|
this.closed = true
|
|
808
808
|
this.id = null
|
|
809
|
-
this.
|
|
809
|
+
this.runtimeInfo = this.state.runtimeInfo
|
|
810
|
+
this.bridge = this.runtimeInfo?.bridge ?? null
|
|
810
811
|
this.entry = this.bridge === null ? entry : `${this.bridge}${entry}`
|
|
811
812
|
this.sessname = sessname
|
|
812
813
|
this.appkin = appkin
|
|
@@ -1019,7 +1020,7 @@ class Window extends GuiCtrl {
|
|
|
1019
1020
|
preload: require.main.filename,
|
|
1020
1021
|
...(decal === false ? { session } : {}),
|
|
1021
1022
|
partition: 'persist:pear',
|
|
1022
|
-
additionalArguments: [JSON.stringify({ ...this.state.config, isDecal: true })],
|
|
1023
|
+
additionalArguments: [JSON.stringify({ ...this.state.config, runtimeInfo: this.runtimeInfo, isDecal: true })],
|
|
1023
1024
|
autoHideMenuBar: true,
|
|
1024
1025
|
experimentalFeatures: true,
|
|
1025
1026
|
nodeIntegration: true,
|
|
@@ -1118,7 +1119,7 @@ class Window extends GuiCtrl {
|
|
|
1118
1119
|
webPreferences: {
|
|
1119
1120
|
preload: require.main.filename,
|
|
1120
1121
|
session,
|
|
1121
|
-
additionalArguments: [JSON.stringify({ ...this.state.config, parentWcId: this.win.webContents.id, decalled: true })],
|
|
1122
|
+
additionalArguments: [JSON.stringify({ ...this.state.config, runtimeInfo: this.runtimeInfo, parentWcId: this.win.webContents.id, decalled: true })],
|
|
1122
1123
|
autoHideMenuBar: true,
|
|
1123
1124
|
experimentalFeatures: true,
|
|
1124
1125
|
nodeIntegration: true,
|
|
@@ -1321,7 +1322,7 @@ class View extends GuiCtrl {
|
|
|
1321
1322
|
webPreferences: {
|
|
1322
1323
|
preload: require.main.filename,
|
|
1323
1324
|
session,
|
|
1324
|
-
additionalArguments: [JSON.stringify({ ...this.state.config, ...(options?.view?.config || options.config || {}), parentWcId: this.win.webContents.id })],
|
|
1325
|
+
additionalArguments: [JSON.stringify({ ...this.state.config, ...(options?.view?.config || options.config || {}), runtimeInfo: this.runtimeInfo, parentWcId: this.win.webContents.id })],
|
|
1325
1326
|
autoHideMenuBar: true,
|
|
1326
1327
|
experimentalFeatures: true,
|
|
1327
1328
|
nodeIntegration: true,
|
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,7 +70,7 @@ 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
75
|
argv = [BOOT, '--runtime-info', info, ...argv]
|
|
76
76
|
const stdio = args.detach ? 'ignore' : ['ignore', 'inherit', 'pipe', 'pipe']
|