From 1ba4b9721ab55e33f6deac5dda06915a7a18e2bc Mon Sep 17 00:00:00 2001 From: ravenclaw900 <50060110+ravenclaw900@users.noreply.github.com> Date: Sun, 3 Oct 2021 12:07:55 -0500 Subject: [PATCH] feat(frontend): show updates to DietPi --- src/backend/src/sockets.rs | 10 ++++++++++ src/backend/src/systemdata.rs | 7 +++++++ src/backend/src/types.rs | 7 ++++++- src/frontend/src/App.svelte | 14 +++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/backend/src/sockets.rs b/src/backend/src/sockets.rs index f50b711f..b20ffbe9 100644 --- a/src/backend/src/sockets.rs +++ b/src/backend/src/sockets.rs @@ -189,18 +189,28 @@ pub async fn socket_handler(socket: warp::ws::WebSocket) { if data.is_close() { break; } + dbg!(&data); req = serde_json::from_str(data.to_str().unwrap()).unwrap(); data_send.send(req.clone()).unwrap(); + println!("sent data {:?}", req); if req.cmd.is_empty() { if first_message { first_message = false; } else { quit.swap(true, Relaxed); + println!("sent quit"); } } } }); + // Send global message (shown on all pages) + let _send = socket_send + .send(Message::text( + serde_json::to_string(&systemdata::global()).unwrap(), + )) + .await; while let Ok(message) = data_recv.recv().await { + println!("got msg, {}", message.page); match message.page.as_str() { "/" => main_handler(&mut socket_send, &quit_clone).await, "/process" => { diff --git a/src/backend/src/systemdata.rs b/src/backend/src/systemdata.rs index f31d36d5..951b4a81 100644 --- a/src/backend/src/systemdata.rs +++ b/src/backend/src/systemdata.rs @@ -290,3 +290,10 @@ pub fn services() -> Vec { } services_list } + +pub fn global() -> types::GlobalData { + let update = + fs::read_to_string("/run/dietpi/.update_available").unwrap_or_else(|_| String::new()); + dbg!(&update); + types::GlobalData { update } +} diff --git a/src/backend/src/types.rs b/src/backend/src/types.rs index 6c9ee26b..1c247903 100644 --- a/src/backend/src/types.rs +++ b/src/backend/src/types.rs @@ -71,7 +71,7 @@ pub struct HostData { pub upgrades: u32, } -#[derive(serde::Serialize, Debug)] +#[derive(serde::Serialize)] pub struct ServiceData { pub name: String, pub log: String, @@ -83,3 +83,8 @@ pub struct ServiceData { pub struct ServiceList { pub services: Vec, } + +#[derive(serde::Serialize)] +pub struct GlobalData { + pub update: String, +} diff --git a/src/frontend/src/App.svelte b/src/frontend/src/App.svelte index 1d997928..0d597004 100755 --- a/src/frontend/src/App.svelte +++ b/src/frontend/src/App.svelte @@ -25,7 +25,8 @@ software?: software[]; response?: string; processes?: processes[]; - services: services[]; + services?: services[]; + update?: string; } interface software { @@ -58,8 +59,13 @@ let socketData: socketData = {}; let shown = false; let menu = window.innerWidth > 768; + let update = ""; + const socketMessageListener = (e) => { socketData = JSON.parse(e.data); + if (socketData.update != undefined) { + update = socketData.update; + } }; const socketOpenListener = () => { console.log("Connected"); @@ -82,6 +88,7 @@ function pollServer() { socket.send(JSON.stringify({ page: window.location.pathname })); + //update = ""; } onMount(() => { @@ -145,6 +152,11 @@ class="h-10" /> + {#if update != undefined} + DietPi update avalible: {update} + {/if}
{#if shown}