fix: process LTC frames in background to update app state

Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-07-28 23:43:28 +01:00
parent 985ccc6819
commit 6a45660e03

View file

@ -151,19 +151,23 @@ async fn main() {
}); });
} }
// 8⃣ Keep main thread alive // 8⃣ Main logic loop: process frames from serial and update state
let loop_state = ltc_state.clone();
let logic_task = task::spawn_blocking(move || {
for frame in rx {
loop_state.lock().unwrap().update(frame);
}
});
// 9⃣ Keep main thread alive
if args.command.is_some() { if args.command.is_some() {
// In daemon mode, wait forever. // In daemon mode, wait forever. The logic_task runs in the background.
std::future::pending::<()>().await; std::future::pending::<()>().await;
} else { } else {
// In TUI mode, block on the channel. // In TUI mode, block until the logic_task finishes (e.g. serial port disconnects)
// This keeps the TUI running.
log::info!("📡 Main thread entering loop..."); log::info!("📡 Main thread entering loop...");
let _ = task::spawn_blocking(move || { let _ = logic_task.await;
for _frame in rx {
// no-op
}
})
.await;
} }
}) })
.await; .await;