From a5fab8403fd9ca71d50e2b668d9615294e3efc60 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Sun, 8 Jun 2025 14:40:15 -0500 Subject: [PATCH] adding client suicide & dev mode --- client/src/app.rs | 15 +++++++-------- scripts/install-client.sh | 7 ++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/client/src/app.rs b/client/src/app.rs index 84b25d8..527f9c5 100644 --- a/client/src/app.rs +++ b/client/src/app.rs @@ -1,6 +1,6 @@ use anyhow::{Context, Result}; use tokio::sync::mpsc; -use tokio::time::{timeout, Duration}; +use tokio::time::Duration; use tokio_stream::wrappers::ReceiverStream; use tonic::Request; use tracing::info; @@ -41,14 +41,14 @@ impl NavkaClientApp { // 3) Start reading from all keyboards in a background task let mut aggregator = KeyboardAggregator::new(tx.clone()); aggregator.init_devices()?; // discover & grab - let mut kb_handle = tokio::spawn(async move { + let kb_handle = tokio::spawn(async move { if let Err(e) = aggregator.run().await { tracing::error!("KeyboardAggregator failed: {e}"); } }); // 4) Add 30 second suicide for dev mode - let mut suicide_fut = async { + let suicide_fut = async { if std::env::var_os("NAVKA_DEV_MODE").is_some() { tracing::info!("DEV-mode: will exit in 30 s"); tokio::time::sleep(Duration::from_secs(30)).await; @@ -59,7 +59,7 @@ impl NavkaClientApp { }; // 5) Inbound loop: we do something with reports from the server, e.g. logging: - let mut inbound_fut = async { + let inbound_fut = async { while let Some(report) = inbound.message().await? { tracing::debug!(?report.data, "msg from server"); } @@ -68,19 +68,18 @@ impl NavkaClientApp { // 6) Race the futures tokio::select! { - res = &mut inbound_fut => { + res = inbound_fut => { tracing::warn!("Inbound stream ended: {res:?}"); }, - res = &mut kb_handle => { + res = kb_handle => { tracing::warn!("Keyboard task finished: {res:?}"); }, - res = &mut suicide_fut => { + res = suicide_fut => { tracing::warn!("Dev-mode shutdown: {res:?}"); }, } // 7) If inbound stream ends, stop the input task - kb_handle.abort(); Ok(()) } } diff --git a/scripts/install-client.sh b/scripts/install-client.sh index aa57d93..c5b4c61 100755 --- a/scripts/install-client.sh +++ b/scripts/install-client.sh @@ -47,10 +47,7 @@ Restart=no WantedBy=default.target EOF -# 7) (Optional) keep running when no session is active -loginctl enable-linger "$ORIG_USER" - # 8) Call the *user* instance inside the caller’s session -sudo -iu "$ORIG_USER" systemctl daemon-reload -sudo -iu "$ORIG_USER" systemctl enable --now navka-client.service +sudo systemctl daemon-reload +sudo systemctl enable --now navka-client.service sudo systemctl restart navka-server