/** * 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 }