ChatGPT Codex 5.5 xhigh refactored even more
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
//! 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<PeerEvent>, ctx: Ctx) {
|
||||
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 {
|
||||
interval.tick().await;
|
||||
|
||||
let game_dir = { ctx.game_dir.read().await.clone() };
|
||||
if let Some(game_dir) = game_dir {
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user