adding client suicide & dev mode
This commit is contained in:
parent
c3375a6541
commit
a5fab8403f
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user