feat: add auth route, update machine status
Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
4578a43197
commit
60424ebe5a
11 changed files with 107 additions and 20 deletions
|
|
@ -8,7 +8,7 @@ Idea, Issue, Work Tracking
|
|||
- [] #3: Save value to recipe
|
||||
- [] #6: display all recipes with materials from csv [material usages with product code]
|
||||
- [] #7: material & menu creation
|
||||
- [x] #8: change recipe version
|
||||
- [] #9: show & edit price
|
||||
|
||||
[Rejected]
|
||||
- [] #4: From #1, will do sync value from server, so that user could save their current edit too
|
||||
|
|
@ -18,5 +18,6 @@ Idea, Issue, Work Tracking
|
|||
- [x] #1: Topping value saving bug, fix by snapshot value
|
||||
- [x] #2: Send change value from editing in recipe to machine
|
||||
- [x] #5: revert value on close dialog recipe
|
||||
- [x] #8: change recipe version
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
recipeFromServerQuery,
|
||||
referenceFromPage
|
||||
} from '$lib/core/stores/recipeStore';
|
||||
import { onMount } from 'svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { MediaQuery } from 'svelte/reactivity';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
|
|
@ -25,7 +25,11 @@
|
|||
import { sendMessage } from '$lib/core/handlers/ws_messageSender';
|
||||
import { auth } from '$lib/core/stores/auth';
|
||||
import { departmentStore } from '$lib/core/stores/departments';
|
||||
import { getMachineStatus, machineInfoStore } from '$lib/core/stores/machineInfoStore';
|
||||
import {
|
||||
getMachineStatus,
|
||||
machineInfoStore,
|
||||
updateMachineStatus
|
||||
} from '$lib/core/stores/machineInfoStore';
|
||||
|
||||
const isDesktop = new MediaQuery('(min-width: 768px)');
|
||||
|
||||
|
|
@ -49,6 +53,8 @@
|
|||
let callback_revert_value_if_not_save: any = $state(() => {});
|
||||
let save_change: boolean = $state(false);
|
||||
|
||||
let interval_get_machine_status: any;
|
||||
|
||||
async function onPendingChange(newChange: { target: string; value: any; ref_pd: string }) {
|
||||
console.log('detect pending change', matchMenuStatus(currentData.MenuStatus));
|
||||
hasPendingChange = true;
|
||||
|
|
@ -244,7 +250,9 @@
|
|||
console.log('sending brewing payload', ready_to_send_brew);
|
||||
|
||||
// save topping
|
||||
latestRecipeToppingData.set(ready_to_send_brew[0]['ToppingSet']);
|
||||
|
||||
if (ready_to_send_brew.length > 1)
|
||||
latestRecipeToppingData.set(ready_to_send_brew[0]['ToppingSet']);
|
||||
|
||||
await sendToAndroid({
|
||||
type: 'brew',
|
||||
|
|
@ -295,6 +303,30 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
// interval check 1s
|
||||
// machine
|
||||
interval_get_machine_status = setInterval(() => {
|
||||
if (getMachineStatus() == undefined) {
|
||||
// set default now
|
||||
updateMachineStatus('');
|
||||
}
|
||||
|
||||
// update machine status
|
||||
// check-connection
|
||||
sendToAndroid({
|
||||
type: 'check-connection',
|
||||
payload: {
|
||||
start: new Date().toLocaleTimeString()
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
clearInterval(interval_get_machine_status);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if isDesktop.current}
|
||||
|
|
|
|||
|
|
@ -236,6 +236,11 @@ async function connectToAndroidServer() {
|
|||
addNotification('INFO:Enable Brewing Mode T on machine');
|
||||
} else {
|
||||
addNotification('WARN:Brewing Mode T unavailable');
|
||||
|
||||
setTimeout(async () => {
|
||||
console.log('reconnecting android server');
|
||||
await connectToAndroidServer();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
}
|
||||
})
|
||||
);
|
||||
} else if (raw_payload.startsWith('state')) {
|
||||
let res = raw_payload.split('/');
|
||||
let new_machine_state = res[1] ?? '';
|
||||
|
||||
if (new_machine_state != '') {
|
||||
updateMachineStatus(new_machine_state.replace('MACHINE_STATE_', ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -68,6 +75,7 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
let total_time = plist[1] ?? '';
|
||||
|
||||
// update recipe data store
|
||||
console.log('brewing finish', pd, 'total time', total_time);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ async function sendToAndroid(message: any) {
|
|||
let writer: any = get(adbWriter);
|
||||
console.log('writer', writer);
|
||||
if (!writer) {
|
||||
addNotification('ERR:No active connection');
|
||||
// addNotification('ERR:No active connection');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const encoder = new TextEncoder();
|
||||
console.log(writer);
|
||||
// console.log(writer);
|
||||
await writer.write(encoder.encode(JSON.stringify(message) + '\n'));
|
||||
console.log('sent! ', JSON.stringify(message));
|
||||
console.log('sent! ', JSON.stringify(message).length);
|
||||
} catch (error) {
|
||||
console.error('write failed', error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export const socketConnectionOfflineCount = writable<number>(0);
|
|||
export const socketAlreadySendHeartbeat = writable<number>(0);
|
||||
export const socketStore = writable<WebSocket | null>(null);
|
||||
|
||||
export function connectToWebsocket() {
|
||||
export function connectToWebsocket(id_token?: string) {
|
||||
if (browser) {
|
||||
// console.log('connecting to ', env.PUBLIC_WSS);
|
||||
try {
|
||||
|
|
@ -24,7 +24,10 @@ export function connectToWebsocket() {
|
|||
return;
|
||||
}
|
||||
|
||||
socket = new WebSocket(`${env.PUBLIC_WSS}`);
|
||||
let productionMode = env.PUBLIC_WSS.startsWith('wss');
|
||||
|
||||
let ws_url = productionMode ? `${env.PUBLIC_WSS}?token=${id_token}` : `${env.PUBLIC_WSS}`;
|
||||
socket = new WebSocket(ws_url);
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
socketStore.set(socket);
|
||||
|
|
@ -64,7 +67,7 @@ export function connectToWebsocket() {
|
|||
socketConnectionOfflineCount.set(0);
|
||||
socketAlreadySendHeartbeat.set(0);
|
||||
|
||||
connectToWebsocket();
|
||||
connectToWebsocket(id_token);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -87,7 +90,7 @@ export function connectToWebsocket() {
|
|||
console.log('try reconnect websocket ...');
|
||||
// retry again
|
||||
reconnectTimeout = setTimeout(() => {
|
||||
connectToWebsocket();
|
||||
connectToWebsocket(id_token);
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
|
@ -103,7 +106,7 @@ export function connectToWebsocket() {
|
|||
if (auth.currentUser && !socket) {
|
||||
console.log('try reconnect websocket ...');
|
||||
// retry again
|
||||
reconnectTimeout = setTimeout(() => connectToWebsocket(), 5000);
|
||||
reconnectTimeout = setTimeout(() => connectToWebsocket(id_token), 5000);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
|
||||
console.log('error on authed page route, ', page);
|
||||
|
||||
setTimeout(() => {
|
||||
goto('/entry');
|
||||
}, 3000);
|
||||
</script>
|
||||
|
||||
<h1>{page.status} {page.error?.message}</h1>
|
||||
<h1>{page.status} {page.error?.message}</h1>
|
||||
|
|
|
|||
|
|
@ -65,10 +65,21 @@
|
|||
let currentUser = get(auth);
|
||||
// console.log(`on mount layout current user: ${JSON.stringify(currentUser)}`);
|
||||
if (currentUser) {
|
||||
connectToWebsocket();
|
||||
// console.log('id', await currentUser.getIdToken());
|
||||
|
||||
console.log('connect ws on mount');
|
||||
connectToWebsocket(await currentUser.getIdToken());
|
||||
await tryAutoConnect();
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
console.log('connect ws on effect');
|
||||
|
||||
setTimeout(async () => {
|
||||
connectToWebsocket(await get(auth)?.getIdToken());
|
||||
}, 100);
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@
|
|||
|
||||
// setTimeout(() => recipeLoading.set(false), 3000);
|
||||
}
|
||||
}, 30000);
|
||||
}, 10000);
|
||||
|
||||
version_list = get(currentRecipeVersionsSelector);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
sendCommandRequest('sheet', {
|
||||
country: refDepartment,
|
||||
param: 'get_all_catalogs'
|
||||
param: 'catalogs'
|
||||
});
|
||||
|
||||
// await getRecipes();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,25 @@
|
|||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
// Svelte 5 approach
|
||||
$effect(() => {
|
||||
// Redirect to home after a very brief delay or immediately
|
||||
goto('/');
|
||||
});
|
||||
|
||||
// Fallback for SEO or slow JS: a meta refresh tag
|
||||
</script>
|
||||
|
||||
<h1>{page.status} {page.error?.message}</h1>
|
||||
<svelte:head>
|
||||
<!-- Redirects after 2 seconds if JavaScript fails to load -->
|
||||
<meta http-equiv="refresh" content="2;url=/" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex h-screen flex-col items-center justify-center gap-2">
|
||||
<h1 class="font-sans text-5xl text-foreground">Redirecting...</h1>
|
||||
<p class="my-8 text-xl text-muted-foreground">
|
||||
Something went wrong. Sending you back to the home page.
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue