- fix topping bug where update value also save across states even already closed dialog
- fix disconnect may throw error
- add machine state payload from tcp socket
- add command/sheet api request
- add heartbeat message

Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
pakintada@gmail.com 2026-04-12 10:47:53 +07:00
parent 230e2ec342
commit 916e056389
8 changed files with 78 additions and 30 deletions

View file

@ -136,9 +136,12 @@ export async function executeCmd(command: string) {
export async function disconnect() {
let instance = getAdbInstance();
if (instance) {
await instance.close();
console.log('close instance');
await saveAdbInstance(undefined);
try {
await instance.close();
console.log('close instance');
} finally {
await saveAdbInstance(undefined);
}
}
}

View file

@ -26,6 +26,16 @@ async function handleAdbPayload(raw_payload: string) {
addNotification('ERR:Request rejected');
}
break;
case 'machine':
// machine state
if (payload.payload) {
let states = payload.payload.split('/');
let curr = states[0].replace('MACHINE_STATE_', '');
let next = states[1].replace('MACHINE_STATE_', '');
console.log('current state', curr, 'next state', next);
}
break;
case 'error':
// show error to user from brew app
addNotification(`ERR:${payload.payload}`);

View file

@ -173,7 +173,7 @@ const handlers: Record<string, (payload: any) => void> = {
export function handleIncomingMessages(raw: string) {
const msg: WSMessage = JSON.parse(raw);
console.log(`${new Date().toLocaleTimeString()}:ws msg`, msg);
// console.log(`${new Date().toLocaleTimeString()}:ws msg`, msg);
if (msg == null) {
// error response
addNotification('ERR:No response from server');

View file

@ -2,9 +2,45 @@ import { get, writable } from 'svelte/store';
import type { OutMessage } from '../types/outMessage';
import { socketStore } from '../stores/websocketStore';
import { addNotification } from '../stores/noti';
import { auth } from '../stores/auth';
export const queue = writable<string[]>([]);
type CommandRequest = 'sheet' | 'command';
function getServiceName(cmdReq: CommandRequest) {
switch (cmdReq) {
case 'sheet':
return 'sheet-api';
case 'command':
return 'command';
}
}
// Websocket message wrapper for commands like `sheet`, `command`
export function sendCommandRequest(target: CommandRequest, values: any) {
let srv_name = getServiceName(target);
let curr_user = get(auth);
let user_info: any;
if (curr_user) {
user_info = {
displayName: curr_user.displayName,
email: curr_user.email,
uid: curr_user.uid
};
}
sendMessage({
type: target,
payload: {
user_info: user_info ?? {},
srv_name,
values
}
});
}
export function sendMessage(msg: OutMessage): boolean {
const socket = get(socketStore);
const data = JSON.stringify(msg);

View file

@ -31,4 +31,16 @@ export type OutMessage =
country: string;
values: any;
};
}
| {
type: 'heartbeat';
payload: {};
}
| {
type: 'sheet' | 'command';
payload: {
user_info: any;
srv_name: string;
values: any;
};
};