pear-electron 0.1.1 → 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 +31 -29
- package/gui/preload.js +6 -0
- package/package.json +2 -1
- package/preload.js +11 -8
package/gui/gui.js
CHANGED
|
@@ -1516,6 +1516,8 @@ class PearGUI extends ReadyResource {
|
|
|
1516
1516
|
electron.ipcMain.handle('checkpoint', (evt, ...args) => this.checkpoint(...args))
|
|
1517
1517
|
electron.ipcMain.handle('versions', (evt, ...args) => this.versions(...args))
|
|
1518
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))
|
|
1519
1521
|
|
|
1520
1522
|
electron.ipcMain.on('workerRun', (evt, link, args) => {
|
|
1521
1523
|
const pipe = this.worker.run(link, args)
|
|
@@ -1610,9 +1612,9 @@ class PearGUI extends ReadyResource {
|
|
|
1610
1612
|
win.loadURL('chrome://' + name)
|
|
1611
1613
|
}
|
|
1612
1614
|
|
|
1613
|
-
|
|
1615
|
+
hasCtrl (id) { return GuiCtrl[kMap].has(id) }
|
|
1614
1616
|
|
|
1615
|
-
|
|
1617
|
+
getCtrl (id) {
|
|
1616
1618
|
const instance = GuiCtrl[kMap].get(id)
|
|
1617
1619
|
if (!instance) {
|
|
1618
1620
|
return {
|
|
@@ -1666,7 +1668,7 @@ class PearGUI extends ReadyResource {
|
|
|
1666
1668
|
}
|
|
1667
1669
|
|
|
1668
1670
|
async parent ({ id, act, args }) {
|
|
1669
|
-
const instance = this.
|
|
1671
|
+
const instance = this.getCtrl(id)
|
|
1670
1672
|
if (!instance) throw new Error(`Could not find parent with id "${id}" to perform action "${act}"!`)
|
|
1671
1673
|
if (act === 'focus') return instance.focus(...args)
|
|
1672
1674
|
if (act === 'blur') return instance.blur()
|
|
@@ -1680,69 +1682,69 @@ class PearGUI extends ReadyResource {
|
|
|
1680
1682
|
if (act === 'isFullscreen') return instance.isFullscreen()
|
|
1681
1683
|
}
|
|
1682
1684
|
|
|
1683
|
-
open ({ id, options }) { return this.
|
|
1685
|
+
open ({ id, options }) { return this.getCtrl(id).open(options) }
|
|
1684
1686
|
|
|
1685
1687
|
// guiClose because ReadyResource needs close (affects internal naming only)
|
|
1686
|
-
guiClose ({ id }) { return this.
|
|
1688
|
+
guiClose ({ id }) { return this.getCtrl(id).close() }
|
|
1687
1689
|
|
|
1688
|
-
show ({ id }) { return this.
|
|
1690
|
+
show ({ id }) { return this.getCtrl(id).show() }
|
|
1689
1691
|
|
|
1690
|
-
hide ({ id }) { return this.
|
|
1692
|
+
hide ({ id }) { return this.getCtrl(id).hide() }
|
|
1691
1693
|
|
|
1692
|
-
minimize ({ id }) { return this.
|
|
1694
|
+
minimize ({ id }) { return this.getCtrl(id).minimize() }
|
|
1693
1695
|
|
|
1694
|
-
maximize ({ id }) { return this.
|
|
1696
|
+
maximize ({ id }) { return this.getCtrl(id).maximize() }
|
|
1695
1697
|
|
|
1696
|
-
setMinimizable ({ id, value }) { return this.
|
|
1698
|
+
setMinimizable ({ id, value }) { return this.getCtrl(id).setMinimizable(value) }
|
|
1697
1699
|
|
|
1698
|
-
setMaximizable ({ id, value }) { return this.
|
|
1700
|
+
setMaximizable ({ id, value }) { return this.getCtrl(id).setMaximizable(value) }
|
|
1699
1701
|
|
|
1700
|
-
fullscreen ({ id }) { return this.
|
|
1702
|
+
fullscreen ({ id }) { return this.getCtrl(id).fullscreen() }
|
|
1701
1703
|
|
|
1702
|
-
restore ({ id }) { return this.
|
|
1704
|
+
restore ({ id }) { return this.getCtrl(id).restore() }
|
|
1703
1705
|
|
|
1704
|
-
focus ({ id, options }) { return this.
|
|
1706
|
+
focus ({ id, options }) { return this.getCtrl(id).focus(options) }
|
|
1705
1707
|
|
|
1706
|
-
blur ({ id }) { return this.
|
|
1708
|
+
blur ({ id }) { return this.getCtrl(id).blur() }
|
|
1707
1709
|
|
|
1708
|
-
dimensions ({ id, options }) { return this.
|
|
1710
|
+
dimensions ({ id, options }) { return this.getCtrl(id).dimensions(options) }
|
|
1709
1711
|
|
|
1710
|
-
isVisible ({ id }) { return this.
|
|
1712
|
+
isVisible ({ id }) { return this.getCtrl(id).isVisible() }
|
|
1711
1713
|
|
|
1712
|
-
isClosed ({ id }) { return (this.
|
|
1714
|
+
isClosed ({ id }) { return (this.hasCtrl(id)) ? this.getCtrl(id).isClosed() : true }
|
|
1713
1715
|
|
|
1714
|
-
isMinimized ({ id }) { return this.
|
|
1716
|
+
isMinimized ({ id }) { return this.getCtrl(id).isMinimized() }
|
|
1715
1717
|
|
|
1716
|
-
isMaximized ({ id }) { return this.
|
|
1718
|
+
isMaximized ({ id }) { return this.getCtrl(id).isMaximized() }
|
|
1717
1719
|
|
|
1718
|
-
isFullscreen ({ id }) { return this.
|
|
1720
|
+
isFullscreen ({ id }) { return this.getCtrl(id).isFullscreen() }
|
|
1719
1721
|
|
|
1720
|
-
setSize ({ id, width, height }) { return this.
|
|
1722
|
+
setSize ({ id, width, height }) { return this.getCtrl(id).setSize(width, height) }
|
|
1721
1723
|
|
|
1722
|
-
unloading ({ id }) { return this.
|
|
1724
|
+
unloading ({ id }) { return this.getCtrl(id).unloading() }
|
|
1723
1725
|
|
|
1724
1726
|
async completeUnload ({ id, action }) {
|
|
1725
|
-
const instance = this.
|
|
1727
|
+
const instance = this.getCtrl(id)
|
|
1726
1728
|
if (!instance) return
|
|
1727
1729
|
instance.completeUnload(action)
|
|
1728
1730
|
}
|
|
1729
1731
|
|
|
1730
|
-
async attachMainView ({ id }) { this.
|
|
1732
|
+
async attachMainView ({ id }) { this.getCtrl(id).attachMainView() }
|
|
1731
1733
|
|
|
1732
|
-
async detachMainView ({ id }) { this.
|
|
1734
|
+
async detachMainView ({ id }) { this.getCtrl(id).detachMainView() }
|
|
1733
1735
|
|
|
1734
1736
|
async afterViewLoaded ({ id }) {
|
|
1735
|
-
return this.
|
|
1737
|
+
return this.getCtrl(id).afterViewLoaded()
|
|
1736
1738
|
}
|
|
1737
1739
|
|
|
1738
1740
|
async setWindowButtonPosition ({ id, point }) {
|
|
1739
|
-
const instance = this.
|
|
1741
|
+
const instance = this.getCtrl(id)
|
|
1740
1742
|
if (!instance) return
|
|
1741
1743
|
instance.setWindowButtonPosition(point)
|
|
1742
1744
|
}
|
|
1743
1745
|
|
|
1744
1746
|
async setWindowButtonVisibility ({ id, visible }) {
|
|
1745
|
-
const instance = this.
|
|
1747
|
+
const instance = this.getCtrl(id)
|
|
1746
1748
|
if (!instance) return
|
|
1747
1749
|
instance.setWindowButtonVisibility(visible)
|
|
1748
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>
|