- 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

@ -48,7 +48,7 @@
let socket = get(socketStore);
if (socket) {
socket.close(1011, 'logout');
socket.close(1000, 'logout');
}
socketStore.set(null);

View file

@ -215,9 +215,9 @@
// set to edit state even if selected same group again
value_event_state = ValueEvent.EDITED;
if (current_editing_data['toppings']) {
if (current_editing_data['toppings'] == undefined || current_editing_data['toppings'] == null) {
let toppings_length = current_editing_data['toppings'].length;
if (!changed_data['toppings']) {
if (changed_data['toppings'] == undefined || changed_data['toppings'] == null) {
changed_data['toppings'] = new Array<any>(toppings_length);
// console.log('filling change topping', JSON.stringify(changed_data));
@ -250,10 +250,10 @@
// set to edit state even if selected same group again
value_event_state = ValueEvent.EDITED;
let idx = getToppingSlotIndex(current_editing_data['mat_id']);
if (current_editing_data['toppings']) {
if (current_editing_data['toppings'] == undefined || current_editing_data['toppings'] == null) {
let toppings_length = current_editing_data['toppings'].length;
// case: topping not init
if (!changed_data['toppings']) {
if (changed_data['toppings'] == null || changed_data['toppings'] == undefined) {
changed_data['toppings'] = new Array<any>(toppings_length);
}
}
@ -272,25 +272,6 @@
}
}
function beforeClosing() {
if (value_event_state === ValueEvent.EDITED) {
if (warnUserNotSaveChange) {
// Discard all
warnUserNotSaveChange = false;
// sheetOpenState = false;
return true;
} else {
// show no save warning
warnUserNotSaveChange = true;
return false;
}
} else {
sheetOpenState = false;
return true;
}
}
// recipelist-value-editor.svelte?t=1773541064272:57 GET requested data: {"mat_id":1002,"mat_type":"bean","mat_name":"medium-roasts (1002)","params":{"esp-v2-press-value":"24"},"toppings":[{"ListGroupID":[1,0,0,0],"defaultIDSelect":1,"groupID":"1","isUse":true},{"ListGroupID":[6,0,0,0],"defaultIDSelect":31,"groupID":"6","isUse":true},{"ListGroupID":[7,0,0,0],"defaultIDSelect":33,"groupID":"7","isUse":true},{"ListGroupID":[0,0,0,0],"defaultIDSelect":0,"groupID":"0","isUse":false},{"ListGroupID":[0,0,0,0],"defaultIDSelect":0,"groupID":"0","isUse":false},{"ListGroupID":[0,0,0,0],"defaultIDSelect":0,"groupID":"0","isUse":false},{"ListGroupID":[530,0,0,0],"defaultIDSelect":532,"groupID":"530","isUse":true},{"ListGroupID":[500,0,0,0],"defaultIDSelect":502,"groupID":"500","isUse":true}],"current_topping_list":[],"has_mix_ord":false,"feed":{"pattern":0,"parameter":0},"water":{"cold":0,"yield":30},"powder":{"gram":7,"time":9},"syrup":{"gram":0,"time":0},"stir_time":120}
// recipelist-value-editor.svelte?t=1773541064272:79 sending request edit 0
// recipelist-value.svelte:224 request edit mat

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;
};
};

View file

@ -11,7 +11,7 @@
recipeOverviewData,
referenceFromPage
} from '$lib/core/stores/recipeStore.js';
import { sendMessage } from '$lib/core/handlers/ws_messageSender.js';
import { sendCommandRequest, sendMessage } from '$lib/core/handlers/ws_messageSender.js';
import { auth } from '$lib/core/stores/auth.js';
import { get } from 'svelte/store';
import { getRecipes } from '$lib/core/client/server.js';
@ -24,6 +24,12 @@
// loadRecipe();
refDepartment = get(departmentStore);
referenceFromPage.set('overview');
sendCommandRequest('sheet', {
country: refDepartment,
param: 'get_all_catalogs'
});
// await getRecipes();
});
@ -39,7 +45,7 @@
<div>
<h1 class="m-8 text-4xl font-bold">Layout overview [ {refDepartment} ]</h1>
<p class="mx-8 my-0 text-muted-foreground">
Display menus from the spreadsheet current selected country
Display menus from the spreadsheet current selected country
</p>
</div>
<div class="mx-8 my-4 flex gap-2">