Files
flying-jib/electron/backend.mjs
T
2026-07-31 02:05:43 -04:00

62 lines
1.5 KiB
JavaScript

/**
* Bare/Node backend for the Electron desktop shell.
* Starts App + loopback gui-control; writes gui-control.json under FJ_STORAGE.
*
* Spawned by electron/main.cjs via bare-runtime (not Electron's Node ABI).
*/
import process from 'process'
import path from 'path'
import pkg from '../package.json' with { type: 'json' }
import App from '../app.js'
import { start as startGuiControl } from '../lib/gui-control.js'
const storage = process.env.FJ_STORAGE
if (!storage) {
console.error('[flying-jib] FJ_STORAGE is required')
process.exit(1)
}
const appName = pkg.productName || pkg.name
const app = new App({
dir: storage,
appPath: null,
updates: false,
version: pkg.version,
upgrade: pkg.upgrade,
name: appName,
displayName: 'player'
})
app.on('error', (err) => console.error('[flying-jib]', err))
app.on('message', (m) => console.log('[flying-jib]', m))
await app.ready()
const sep = storage.includes('\\') ? '\\' : '/'
const statePath = storage.endsWith(sep)
? `${storage}gui-control.json`
: `${storage}${sep}gui-control.json`
const control = await startGuiControl({ app, statePath })
console.log(`[flying-jib] GUI control at ${control.baseUrl}`)
async function shutdown() {
try {
await control.close?.()
} catch {
// ignore
}
try {
await app.exit(0)
} catch {
// ignore
}
process.exit(0)
}
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
if (typeof Bare !== 'undefined') {
Bare.on('exit', shutdown)
}