Skip to content

Commit

Permalink
fix: don't push changes to service and management pages
Browse files Browse the repository at this point in the history
The services page only used changes for updating the time, which wasn't really worth it if there was more than a minute on the timer. Management has been switched to a minute instead of seconds, which won't be updated without re-clicking the tab.
  • Loading branch information
ravenclaw900 committed Nov 10, 2021
1 parent 122c38b commit 9bd3033
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
47 changes: 21 additions & 26 deletions src/backend/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,15 @@ async fn management_handler(
socket_ptr: Arc<Mutex<SplitSink<warp::ws::WebSocket, warp::ws::Message>>>,
data_recv: &mut Receiver<Option<types::Request>>,
) {
let handle = tokio::spawn(async move {
loop {
let mut socket_send = socket_ptr.lock().await;
let _send = (*socket_send)
.send(Message::text(SerJson::serialize_json(
&systemdata::host().await,
)))
.await;
sleep(Duration::from_secs(1)).await;
}
});
let mut socket_send = socket_ptr.lock().await;
let _send = (*socket_send)
.send(Message::text(SerJson::serialize_json(
&systemdata::host().await,
)))
.await;
loop {
match data_recv.recv().await {
Some(None) | None => {
handle.abort();
break;
}
Some(Some(data)) => {
Expand All @@ -161,30 +155,31 @@ async fn service_handler(
socket_ptr: Arc<Mutex<SplitSink<warp::ws::WebSocket, warp::ws::Message>>>,
data_recv: &mut Receiver<Option<types::Request>>,
) {
let handle = tokio::spawn(async move {
loop {
let mut socket_send = socket_ptr.lock().await;
let _send = (*socket_send)
.send(Message::text(SerJson::serialize_json(
&types::ServiceList {
services: systemdata::services(),
},
)))
.await;
sleep(Duration::from_secs(2)).await;
}
});
let mut socket_send = socket_ptr.lock().await;
let _send = (*socket_send)
.send(Message::text(SerJson::serialize_json(
&types::ServiceList {
services: systemdata::services(),
},
)))
.await;
loop {
match data_recv.recv().await {
Some(None) | None => {
handle.abort();
break;
}
Some(Some(data)) => {
Command::new("systemctl")
.args([data.cmd, (&*data.args[0]).to_string()])
.spawn()
.unwrap();
let _send = (*socket_send)
.send(Message::text(SerJson::serialize_json(
&types::ServiceList {
services: systemdata::services(),
},
)))
.await;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/src/systemdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use heim::{
units::{
information::{byte, mebibyte},
ratio::percent,
time::second,
time::minute,
},
};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn dpsoftware() -> Vec<types::DPSoftwareData> {
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
pub async fn host() -> types::HostData {
let info = host::platform().await.unwrap();
let uptime = host::uptime().await.unwrap().get::<second>().round() as u64;
let uptime = host::uptime().await.unwrap().get::<minute>().round() as u64;
let dp_file = fs::read_to_string(&std::path::Path::new("/boot/dietpi/.version")).unwrap();
let dp_version: Vec<&str> = dp_file.split(&['=', '\n'][..]).collect();
let installed_pkgs = from_utf8(
Expand Down
Binary file modified src/frontend/.yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/frontend/src/pages/Management.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let msg = "";
$: socketData.uptime &&
((uptime = humanizeDuration(socketData.uptime * 1000)),
((uptime = humanizeDuration(socketData.uptime * 60000)),
(dialog = false));
function sendData(data) {
Expand Down

0 comments on commit 9bd3033

Please sign in to comment.