Add 20 Pear/Bare platform modules replacing deprecated pear run.
Introduces hyper-bare-entry-runner, pear-runtime embed/link/config stack, and scaffold helpers for argv, storage, OTA, Electron, and headless UI. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.0-scaffold
|
||||
|
||||
- Initial Pear platform module.
|
||||
@@ -0,0 +1,9 @@
|
||||
# hyper-pear-electron-bridge
|
||||
|
||||
**Protocol:** `pear-electron-bridge/v1`
|
||||
|
||||
Electron renderer IPC bridge. See [`docs/api.md`](docs/api.md).
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
# API: hyper-pear-electron-bridge
|
||||
|
||||
**Protocol:** `pear-electron-bridge/v1` · **Export:** `{ HyperPearElectronBridge, PROTOCOL }`
|
||||
|
||||
See [`index.js`](../index.js) for methods and `getStats()`.
|
||||
@@ -0,0 +1,3 @@
|
||||
# Architecture: hyper-pear-electron-bridge
|
||||
|
||||
Pear/Bare platform module. Replaces or complements deprecated `pear run` flows via embeddable `pear-runtime`.
|
||||
@@ -0,0 +1,9 @@
|
||||
require('bare-process/global')
|
||||
const { HyperPearElectronBridge } = require('../index.js')
|
||||
async function main () {
|
||||
const m = new HyperPearElectronBridge()
|
||||
await m.ready()
|
||||
console.log(m.getStats())
|
||||
await m.close()
|
||||
}
|
||||
main().catch((e) => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,47 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const { assertId, platformStats } = require('../../_shared/pear-platform-base.js')
|
||||
|
||||
const PROTOCOL = 'pear-electron-bridge/v1'
|
||||
|
||||
class HyperPearElectronBridge extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this.renderer = opts.renderer === true
|
||||
this._channels = new Map()
|
||||
this._stats = { ipc: 0 }
|
||||
}
|
||||
|
||||
registerIpc (name, handler) {
|
||||
const n = assertId(name, 'name')
|
||||
if (typeof handler !== 'function') throw new Error('handler must be a function')
|
||||
this._channels.set(n, handler)
|
||||
return () => this._channels.delete(n)
|
||||
}
|
||||
|
||||
invoke (name, payload) {
|
||||
const h = this._channels.get(assertId(name))
|
||||
if (!h) throw new Error(`ipc not registered: ${name}`)
|
||||
this._stats.ipc++
|
||||
const result = h(payload)
|
||||
this.emit('invoke', { name, payload })
|
||||
return result
|
||||
}
|
||||
|
||||
runFromRenderer (link, args = []) {
|
||||
if (!this.renderer) {
|
||||
throw new Error('runFromRenderer requires renderer mode')
|
||||
}
|
||||
this._stats.ipc++
|
||||
return { link, args, via: 'ipc.run' }
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return platformStats(this._stats, PROTOCOL, { handlers: this._channels.size, renderer: this.renderer })
|
||||
}
|
||||
|
||||
async ready () { return this }
|
||||
async close () { this._channels.clear(); this.emit('closed') }
|
||||
}
|
||||
|
||||
module.exports = { HyperPearElectronBridge, HyperP2PPearElectronBridge: HyperPearElectronBridge, PROTOCOL }
|
||||
+1286
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "hyper-pear-electron-bridge",
|
||||
"version": "0.0.0-scaffold",
|
||||
"description": "Electron renderer IPC bridge.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": { "test": "brittle-bare test/test.js" },
|
||||
"dependencies": {
|
||||
"bare-events": "^2.8.0",
|
||||
"bare-process": "^4.4.0",
|
||||
"b4a": "^1.6.7",
|
||||
"hypercore-crypto": "^3.0.0"
|
||||
},
|
||||
"peerDependencies": { "bare": ">=1.0.0" },
|
||||
"devDependencies": { "brittle": "^3.0.0" },
|
||||
"imports": {
|
||||
"process": { "bare": "bare-process", "default": "process" },
|
||||
"events": { "bare": "bare-events", "default": "events" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperPearElectronBridge } = require('../index.js')
|
||||
|
||||
test('ipc invoke', async (t) => {
|
||||
const b = new HyperPearElectronBridge({ renderer: true })
|
||||
b.registerIpc('run', (p) => ({ ok: true, p }))
|
||||
t.ok(b.invoke('run', { link: 'pear://x' }).ok)
|
||||
await b.close()
|
||||
})
|
||||
Reference in New Issue
Block a user