feat: migrate recipe editor
- using eventbus in recipe editor - migrate to logging instead of console log - fix case swap not saved, value not update after change, topping slot bug Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
270faf6b34
commit
f0619c5a10
65 changed files with 1600 additions and 557 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { logger } from '$lib/core/utils/logger';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { addNotification, notiStore } from '../stores/noti';
|
||||
import {
|
||||
|
|
@ -51,6 +52,7 @@ import { env } from '$env/dynamic/public';
|
|||
import * as semver from 'semver';
|
||||
import { WebCryptoHelper } from '../utils/crypto';
|
||||
import { GlobalEventBus } from '../utils/eventBus';
|
||||
import { handleIncomingRemoteShell } from '../stores/remoteShellStore';
|
||||
|
||||
export const messages = writable<string[]>([]);
|
||||
|
||||
|
|
@ -60,7 +62,7 @@ type WSMessage = { type: string; payload: any };
|
|||
// MAXIMUM LIMIT = 1814355
|
||||
const handlers: Record<string, (payload: any) => void> = {
|
||||
chat: (p) => messages.update((m) => [...m, p]),
|
||||
ping: (p) => console.log('ping from server'),
|
||||
ping: (p) => logger.info('ping from server'),
|
||||
recipeResponse: (p) => {
|
||||
let recipe_result = p.result;
|
||||
let recipe_request = p.request;
|
||||
|
|
@ -109,7 +111,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
},
|
||||
stream_data_chunk: (p) => {
|
||||
let current_meta = get(recipeStreamMeta);
|
||||
// console.log('current meta', current_meta);
|
||||
// logger.info('current meta', current_meta);
|
||||
if (current_meta) {
|
||||
let stream_id = current_meta.id;
|
||||
|
||||
|
|
@ -146,7 +148,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
// build overview for recipe from server
|
||||
//
|
||||
|
||||
// console.log('ending stream');
|
||||
// logger.info('ending stream');
|
||||
buildOverviewFromServer();
|
||||
|
||||
let current_meta = get(recipeStreamMeta);
|
||||
|
|
@ -201,7 +203,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
curr_mat_query.push(m);
|
||||
}
|
||||
|
||||
// // console.log('current materials: ', JSON.stringify(curr_mat_query));
|
||||
// // logger.info('current materials: ', JSON.stringify(curr_mat_query));
|
||||
materialFromServerQuery.set(curr_mat_query);
|
||||
break;
|
||||
case 'topplist':
|
||||
|
|
@ -285,7 +287,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
addNotification(`ERR:Gen Layout error: ${msg}`);
|
||||
break;
|
||||
default:
|
||||
console.log('[GenService] Received:', level, msg);
|
||||
logger.info('[GenService] Received:', level, msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -319,7 +321,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
break;
|
||||
default:
|
||||
// Handle other content notifications from sheet-service
|
||||
console.log('[Sheet] Received content:', p.content);
|
||||
logger.info('[Sheet] Received content:', p.content);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
@ -368,7 +370,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
|
||||
let content: RecipePrice[] = p.content ?? [];
|
||||
|
||||
console.log('get price length: ', content.length);
|
||||
logger.info('get price length: ', content.length);
|
||||
|
||||
let current_price = get(priceRecipeData);
|
||||
let lastRequestPriceInstance = get(lastRequestSheetPrice);
|
||||
|
|
@ -385,7 +387,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
|
||||
priceRecipeData.set(current_price);
|
||||
|
||||
console.log('check length', saved_product_code_to_get_from_sheet.length);
|
||||
logger.info('check length', saved_product_code_to_get_from_sheet.length);
|
||||
// set command request to stream mode so
|
||||
let request_id = uuidv4();
|
||||
|
||||
|
|
@ -450,7 +452,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
// streamingRawData.set(streamRawInstance);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.log(`end price process error: ${e}`);
|
||||
// logger.info(`end price process error: ${e}`);
|
||||
// }
|
||||
|
||||
// break;
|
||||
|
|
@ -460,7 +462,7 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
heartbeat: (p) => {
|
||||
socketConnectionOfflineCount.set(0);
|
||||
socketAlreadySendHeartbeat.set(0);
|
||||
console.log('heartbeat reset offline count');
|
||||
logger.info('heartbeat reset offline count');
|
||||
},
|
||||
// Raw stream handlers for sheet data (e.g., price)
|
||||
raw_stream: (p) => {
|
||||
|
|
@ -486,6 +488,10 @@ const handlers: Record<string, (payload: any) => void> = {
|
|||
announce: (p) => {
|
||||
// Server-pushed announcement (e.g., closing maintenance)
|
||||
GlobalEventBus.emit('announce', p);
|
||||
},
|
||||
remote_shell: (p) => {
|
||||
// Server requests command execution on connected Android device
|
||||
handleIncomingRemoteShell(p);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -493,7 +499,7 @@ export async function handleIncomingMessages(raw: string, clientPrivateKey: Cryp
|
|||
const APP_VERSION = env.PUBLIC_APP_SEMVER;
|
||||
|
||||
const ack: HandshakeAck = JSON.parse(raw);
|
||||
// console.log(`[WS MSG] type=${msg.type}`, msg.payload);
|
||||
// logger.info(`[WS MSG] type=${msg.type}`, msg.payload);
|
||||
if (ack != null && ack.status === 'authenticated') {
|
||||
// has server response
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue