mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-04 03:40:03 +08:00
Assisted-by: Cindy (https://cindy.app) Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
22 lines
1.1 KiB
JavaScript
22 lines
1.1 KiB
JavaScript
// A separate client process using Desktop's production HTTP/event adapters.
|
|
// No Electron window, credentials, input replay or task runtime is constructed.
|
|
import { createHostClient, startHostEventBridge } from '../../../desktop/src/main/host-delegation.ts';
|
|
|
|
const config = JSON.parse(process.argv[2]);
|
|
const client = createHostClient(config);
|
|
const emit = value => { if (process.connected) process.send(value); };
|
|
const stop = startHostEventBridge({ ...config,
|
|
broadcast: payload => emit({ type: 'event', payload }),
|
|
onInteractionRequest: payload => emit({ type: 'interaction', payload }),
|
|
onConnectionState: state => emit({ type: 'connection', state }),
|
|
onError: () => emit({ type: 'connection-error' }),
|
|
});
|
|
process.on('message', async message => {
|
|
try { emit({ type: 'reply', id: message.id, result: await client.request(message.path, message.body) }); }
|
|
catch (error) { emit({ type: 'reply', id: message.id, error: error.message }); }
|
|
});
|
|
const close = () => { stop(); if (process.connected) process.disconnect(); };
|
|
process.once('SIGTERM', close);
|
|
process.once('SIGINT', close);
|
|
process.once('disconnect', stop);
|