//! Local game directory monitor. use std::time::Duration; use tokio::sync::mpsc::UnboundedSender; use crate::{ PeerEvent, config::LOCAL_GAME_MONITOR_INTERVAL_SECS, context::Ctx, handlers::update_and_announce_games, local_games::scan_local_library, }; /// Monitors the local game directory for changes. pub async fn run_local_game_monitor( tx_notify_ui: UnboundedSender, ctx: Ctx, ) -> eyre::Result<()> { log::info!( "Starting local game directory monitor ({LOCAL_GAME_MONITOR_INTERVAL_SECS}s interval)" ); let mut interval = tokio::time::interval(Duration::from_secs(LOCAL_GAME_MONITOR_INTERVAL_SECS)); loop { tokio::select! { () = ctx.shutdown.cancelled() => return Ok(()), _ = interval.tick() => {} } let game_dir = { ctx.game_dir.read().await.clone() }; match scan_local_library(&game_dir).await { Ok(scan) => { update_and_announce_games(&ctx, &tx_notify_ui, scan).await; } Err(err) => { log::error!("Failed to scan local games directory: {err}"); } } } }