pear-electron 0.1.0 → 0.2.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/gui/gui.js +36 -33
- package/gui/preload.js +6 -0
- package/package.json +2 -1
- package/preload.js +11 -8
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,
|
|
@@ -1515,6 +1516,8 @@ class PearGUI extends ReadyResource {
|
|
|
1515
1516
|
electron.ipcMain.handle('checkpoint', (evt, ...args) => this.checkpoint(...args))
|
|
1516
1517
|
electron.ipcMain.handle('versions', (evt, ...args) => this.versions(...args))
|
|
1517
1518
|
electron.ipcMain.handle('restart', (evt, ...args) => this.restart(...args))
|
|
1519
|
+
electron.ipcMain.handle('get', (evt, ...args) => this.get(...args))
|
|
1520
|
+
electron.ipcMain.handle('exists', (evt, ...args) => this.exists(...args))
|
|
1518
1521
|
|
|
1519
1522
|
electron.ipcMain.on('workerRun', (evt, link, args) => {
|
|
1520
1523
|
const pipe = this.worker.run(link, args)
|
|
@@ -1609,9 +1612,9 @@ class PearGUI extends ReadyResource {
|
|
|
1609
1612
|
win.loadURL('chrome://' + name)
|
|
1610
1613
|
}
|
|
1611
1614
|
|
|
1612
|
-
|
|
1615
|
+
hasCtrl (id) { return GuiCtrl[kMap].has(id) }
|
|
1613
1616
|
|
|
1614
|
-
|
|
1617
|
+
getCtrl (id) {
|
|
1615
1618
|
const instance = GuiCtrl[kMap].get(id)
|
|
1616
1619
|
if (!instance) {
|
|
1617
1620
|
return {
|
|
@@ -1665,7 +1668,7 @@ class PearGUI extends ReadyResource {
|
|
|
1665
1668
|
}
|
|
1666
1669
|
|
|
1667
1670
|
async parent ({ id, act, args }) {
|
|
1668
|
-
const instance = this.
|
|
1671
|
+
const instance = this.getCtrl(id)
|
|
1669
1672
|
if (!instance) throw new Error(`Could not find parent with id "${id}" to perform action "${act}"!`)
|
|
1670
1673
|
if (act === 'focus') return instance.focus(...args)
|
|
1671
1674
|
if (act === 'blur') return instance.blur()
|
|
@@ -1679,69 +1682,69 @@ class PearGUI extends ReadyResource {
|
|
|
1679
1682
|
if (act === 'isFullscreen') return instance.isFullscreen()
|
|
1680
1683
|
}
|
|
1681
1684
|
|
|
1682
|
-
open ({ id, options }) { return this.
|
|
1685
|
+
open ({ id, options }) { return this.getCtrl(id).open(options) }
|
|
1683
1686
|
|
|
1684
1687
|
// guiClose because ReadyResource needs close (affects internal naming only)
|
|
1685
|
-
guiClose ({ id }) { return this.
|
|
1688
|
+
guiClose ({ id }) { return this.getCtrl(id).close() }
|
|
1686
1689
|
|
|
1687
|
-
show ({ id }) { return this.
|
|
1690
|
+
show ({ id }) { return this.getCtrl(id).show() }
|
|
1688
1691
|
|
|
1689
|
-
hide ({ id }) { return this.
|
|
1692
|
+
hide ({ id }) { return this.getCtrl(id).hide() }
|
|
1690
1693
|
|
|
1691
|
-
minimize ({ id }) { return this.
|
|
1694
|
+
minimize ({ id }) { return this.getCtrl(id).minimize() }
|
|
1692
1695
|
|
|
1693
|
-
maximize ({ id }) { return this.
|
|
1696
|
+
maximize ({ id }) { return this.getCtrl(id).maximize() }
|
|
1694
1697
|
|
|
1695
|
-
setMinimizable ({ id, value }) { return this.
|
|
1698
|
+
setMinimizable ({ id, value }) { return this.getCtrl(id).setMinimizable(value) }
|
|
1696
1699
|
|
|
1697
|
-
setMaximizable ({ id, value }) { return this.
|
|
1700
|
+
setMaximizable ({ id, value }) { return this.getCtrl(id).setMaximizable(value) }
|
|
1698
1701
|
|
|
1699
|
-
fullscreen ({ id }) { return this.
|
|
1702
|
+
fullscreen ({ id }) { return this.getCtrl(id).fullscreen() }
|
|
1700
1703
|
|
|
1701
|
-
restore ({ id }) { return this.
|
|
1704
|
+
restore ({ id }) { return this.getCtrl(id).restore() }
|
|
1702
1705
|
|
|
1703
|
-
focus ({ id, options }) { return this.
|
|
1706
|
+
focus ({ id, options }) { return this.getCtrl(id).focus(options) }
|
|
1704
1707
|
|
|
1705
|
-
blur ({ id }) { return this.
|
|
1708
|
+
blur ({ id }) { return this.getCtrl(id).blur() }
|
|
1706
1709
|
|
|
1707
|
-
dimensions ({ id, options }) { return this.
|
|
1710
|
+
dimensions ({ id, options }) { return this.getCtrl(id).dimensions(options) }
|
|
1708
1711
|
|
|
1709
|
-
isVisible ({ id }) { return this.
|
|
1712
|
+
isVisible ({ id }) { return this.getCtrl(id).isVisible() }
|
|
1710
1713
|
|
|
1711
|
-
isClosed ({ id }) { return (this.
|
|
1714
|
+
isClosed ({ id }) { return (this.hasCtrl(id)) ? this.getCtrl(id).isClosed() : true }
|
|
1712
1715
|
|
|
1713
|
-
isMinimized ({ id }) { return this.
|
|
1716
|
+
isMinimized ({ id }) { return this.getCtrl(id).isMinimized() }
|
|
1714
1717
|
|
|
1715
|
-
isMaximized ({ id }) { return this.
|
|
1718
|
+
isMaximized ({ id }) { return this.getCtrl(id).isMaximized() }
|
|
1716
1719
|
|
|
1717
|
-
isFullscreen ({ id }) { return this.
|
|
1720
|
+
isFullscreen ({ id }) { return this.getCtrl(id).isFullscreen() }
|
|
1718
1721
|
|
|
1719
|
-
setSize ({ id, width, height }) { return this.
|
|
1722
|
+
setSize ({ id, width, height }) { return this.getCtrl(id).setSize(width, height) }
|
|
1720
1723
|
|
|
1721
|
-
unloading ({ id }) { return this.
|
|
1724
|
+
unloading ({ id }) { return this.getCtrl(id).unloading() }
|
|
1722
1725
|
|
|
1723
1726
|
async completeUnload ({ id, action }) {
|
|
1724
|
-
const instance = this.
|
|
1727
|
+
const instance = this.getCtrl(id)
|
|
1725
1728
|
if (!instance) return
|
|
1726
1729
|
instance.completeUnload(action)
|
|
1727
1730
|
}
|
|
1728
1731
|
|
|
1729
|
-
async attachMainView ({ id }) { this.
|
|
1732
|
+
async attachMainView ({ id }) { this.getCtrl(id).attachMainView() }
|
|
1730
1733
|
|
|
1731
|
-
async detachMainView ({ id }) { this.
|
|
1734
|
+
async detachMainView ({ id }) { this.getCtrl(id).detachMainView() }
|
|
1732
1735
|
|
|
1733
1736
|
async afterViewLoaded ({ id }) {
|
|
1734
|
-
return this.
|
|
1737
|
+
return this.getCtrl(id).afterViewLoaded()
|
|
1735
1738
|
}
|
|
1736
1739
|
|
|
1737
1740
|
async setWindowButtonPosition ({ id, point }) {
|
|
1738
|
-
const instance = this.
|
|
1741
|
+
const instance = this.getCtrl(id)
|
|
1739
1742
|
if (!instance) return
|
|
1740
1743
|
instance.setWindowButtonPosition(point)
|
|
1741
1744
|
}
|
|
1742
1745
|
|
|
1743
1746
|
async setWindowButtonVisibility ({ id, visible }) {
|
|
1744
|
-
const instance = this.
|
|
1747
|
+
const instance = this.getCtrl(id)
|
|
1745
1748
|
if (!instance) return
|
|
1746
1749
|
instance.setWindowButtonVisibility(visible)
|
|
1747
1750
|
}
|
package/gui/preload.js
CHANGED
|
@@ -226,6 +226,10 @@ module.exports = class PearGUI {
|
|
|
226
226
|
return stream
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
async get (key) {
|
|
230
|
+
return Buffer.from(await ipc.get(key)).toString('utf-8')
|
|
231
|
+
}
|
|
232
|
+
|
|
229
233
|
constructor () {
|
|
230
234
|
if (state.isDecal) {
|
|
231
235
|
this[this.constructor.DECAL] = {
|
|
@@ -309,6 +313,8 @@ class IPC {
|
|
|
309
313
|
checkpoint (...args) { return electron.ipcRenderer.invoke('checkpoint', ...args) }
|
|
310
314
|
versions (...args) { return electron.ipcRenderer.invoke('versions', ...args) }
|
|
311
315
|
restart (...args) { return electron.ipcRenderer.invoke('restart', ...args) }
|
|
316
|
+
get (...args) { return electron.ipcRenderer.invoke('get', ...args) }
|
|
317
|
+
exists (...args) { return electron.ipcRenderer.invoke('exists', ...args) }
|
|
312
318
|
|
|
313
319
|
messages (pattern) {
|
|
314
320
|
electron.ipcRenderer.send('messages', pattern)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-electron",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Pear User-Interface Library for Electron",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "bin.js",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"hyperswarm": "^4.8.4",
|
|
79
79
|
"iambus": "^1.0.3",
|
|
80
80
|
"localdrive": "^1.12.1",
|
|
81
|
+
"node-bare-bundle": "^1.4.2",
|
|
81
82
|
"paparam": "^1.6.1",
|
|
82
83
|
"path": "npm:bare-node-path@^1.0.1",
|
|
83
84
|
"pear-api": "^0.0.17",
|
package/preload.js
CHANGED
|
@@ -19,6 +19,7 @@ module.exports = (state) => {
|
|
|
19
19
|
|
|
20
20
|
const gui = new GUI({ API, state })
|
|
21
21
|
window.Pear = gui.api
|
|
22
|
+
const PearElectron = Pear[Pear.constructor.UI]
|
|
22
23
|
|
|
23
24
|
if (isDecal === false) Object.assign(process.env, env)
|
|
24
25
|
|
|
@@ -55,9 +56,11 @@ module.exports = (state) => {
|
|
|
55
56
|
warn.call(console, msg, ...args)
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
if (Pear.config.options.gui?.preload) {
|
|
60
|
+
const run = require('node-bare-module')
|
|
61
|
+
const key = Pear.config.options.gui.preload
|
|
62
|
+
Pear.get({ key, bundle: true }).then((preload) => {
|
|
63
|
+
run(preload, { mount: '/', entrypoint: key })
|
|
61
64
|
}, console.error).finally(descopeGlobals)
|
|
62
65
|
} else {
|
|
63
66
|
descopeGlobals()
|
|
@@ -181,19 +184,19 @@ module.exports = (state) => {
|
|
|
181
184
|
this.#demax = () => this.root.querySelector('#ctrl').classList.remove('max')
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
async #min () { await
|
|
187
|
+
async #min () { await PearElectron.Window.self.minimize() }
|
|
185
188
|
async #max (e) {
|
|
186
|
-
if (isMac) await
|
|
187
|
-
else await
|
|
189
|
+
if (isMac) await PearElectron.Window.self.fullscreen()
|
|
190
|
+
else await PearElectron.Window.self.maximize()
|
|
188
191
|
e.target.root.querySelector('#ctrl').classList.add('max')
|
|
189
192
|
}
|
|
190
193
|
|
|
191
194
|
async #restore (e) {
|
|
192
|
-
await
|
|
195
|
+
await PearElectron.Window.self.restore()
|
|
193
196
|
e.target.root.querySelector('#ctrl').classList.remove('max')
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
async #close () { await
|
|
199
|
+
async #close () { await PearElectron.Window.self.close() }
|
|
197
200
|
#win () {
|
|
198
201
|
return `
|
|
199
202
|
<style>
|