//! Jarvis app (headless until the Tauri GUI arrives in M5): jarvis-app //! The data folder can also come from JARVIS_DATA_DIR; the bot token from JARVIS_DISCORD_TOKEN. use jarvis_app::discord::CoreEvent; use jarvis_app::services::start_services; use jarvis_app::{debug_log, error_log}; #[tokio::main] async fn main() { let data_dir = std::env::args().nth(1).or_else(|| std::env::var("JARVIS_DATA_DIR").ok()); let Some(data_dir) = data_dir else { error_log!("app", "usage: jarvis-app (or set JARVIS_DATA_DIR)"); std::process::exit(2); }; let mut services = match start_services(std::path::Path::new(&data_dir)).await { Ok(s) => s, Err(e) => { error_log!("app", "could not start: {e}"); std::process::exit(1); } }; loop { tokio::select! { ev = services.events.recv() => match ev { // The conversation loop answers what is heard; here only the shape is logged, never the text. Some(CoreEvent::Final(f)) => debug_log!("app", "heard {} utt={} chars={}", f.heard.speaker_id, f.heard.utt, f.text.chars().count()), Some(_) => {} None => break, }, _ = shutdown_signal() => break, } } services.stop().await; } async fn shutdown_signal() { #[cfg(unix)] { let mut term = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).expect("signal"); tokio::select! { _ = tokio::signal::ctrl_c() => {} _ = term.recv() => {} } } #[cfg(not(unix))] { let _ = tokio::signal::ctrl_c().await; } }