Files
peardock/index.js
T
snxraven 5fbece2bd9
CI / test (push) Successful in 9m58s
Fix Holesail client connect via Bare main HTTP control
pear-run worker RPC timed out from the Electron UI. Run real holesail
in Bare index.js (holesailBareControl) and have the UI call localhost
HTTP instead of loading bare-tcp in the renderer.
2026-07-10 23:19:31 -04:00

72 lines
1.8 KiB
JavaScript

/**
* Pear desktop entrypoint (v2+).
* Boots pear-electron UI + pear-bridge HTTP for the HTML app shell.
* Also starts the Bare-side Holesail local-client control API (real holesail package).
*
* @typedef {import('pear-interface')}
*/
/* global Pear */
import Runtime from 'pear-electron'
import Bridge from 'pear-bridge'
import bareControl from './client/holesailBareControl.cjs'
const bridge = new Bridge()
await bridge.ready()
// Real holesail runs here (Bare has require.addon). UI talks over localhost HTTP.
let holesailControl = null
try {
const start = bareControl.start || bareControl.default?.start
if (typeof start !== 'function') {
throw new Error('holesailBareControl.cjs missing start()')
}
const storage = Pear?.config?.storage
if (!storage) {
console.warn('[peardock] Pear.config.storage missing — holesail local control disabled')
} else {
// Avoid path module quirks across Bare/Node; storage is already absolute
const sep = storage.includes('\\') ? '\\' : '/'
const statePath = storage.endsWith(sep)
? `${storage}peardock-holesail-local.json`
: `${storage}${sep}peardock-holesail-local.json`
holesailControl = await start({ statePath })
console.log(
`[peardock] Holesail local control at ${holesailControl.baseUrl} (state: ${statePath})`
)
}
} catch (err) {
console.error('[peardock] Failed to start Holesail local control:', err)
}
const runtime = new Runtime()
const pipe = await runtime.start({ bridge })
const shutdown = async () => {
try {
await holesailControl?.close?.()
} catch {
// ignore
}
try {
Pear.exit()
} catch {
// ignore if Pear is already shutting down
}
}
pipe.on('close', () => {
shutdown()
})
try {
Pear.teardown?.(async () => {
try {
await holesailControl?.close?.()
} catch {
// ignore
}
})
} catch {
// ignore
}