feat: add brew app connection

- initialize tcp communication with brew app
- WIP value editor sync

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-04-03 17:25:27 +07:00
parent 08f7626dcb
commit 274025ed33
14 changed files with 431 additions and 69 deletions

View file

@ -0,0 +1,46 @@
import { env } from '$env/dynamic/public';
import * as adb from '$lib/core/adb/adb';
class BrewCommandError extends Error {
public readonly field?: string;
constructor(message: string, field?: string) {
super(message);
this.name = 'BrewCommandError';
this.field = field;
}
}
/// Send command to brew app
/// NOTE: app must enable flag `enable_adb_block_watch`
async function sendCommand(type: string, params?: string[]) {
// check instance
let inst = adb.getAdbInstance();
if (inst) {
try {
let cmd = type + ' ' + (params?.join(' ') ?? '');
await adb.push(env.PUBLIC_BREW_CMD_WEB, cmd);
} catch (e) {
throw new BrewCommandError('Command failed', `${e}`);
}
} else {
throw new BrewCommandError('Instance lost');
}
}
async function sendReset() {
let inst = adb.getAdbInstance();
if (inst) {
try {
await adb.push(env.PUBLIC_BREW_CMD_WEB, '');
await adb.push(env.PUBLIC_BREW_CURRENT_RECIPE, '');
await adb.push(env.PUBLIC_BREW_WEB_STATUS, '');
} catch (e) {
throw new BrewCommandError('Reset failed', `${e}`);
}
} else {
throw new BrewCommandError('Instance lost');
}
}
export { sendCommand, sendReset, BrewCommandError };