diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gui/mod.rs b/src/gui/mod.rs index caf97f8..3abe238 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -2,10 +2,12 @@ pub mod message; pub mod question; pub mod util; +use crate::sync; use crate::{db, space_repetition, util::time}; use anyhow::Result; use crossterm::terminal; use rusqlite::Connection; +use std::fs; use std::io::Stdout; use tui::{backend::CrosstermBackend, Terminal}; @@ -27,13 +29,22 @@ pub fn restore_terminal(term: &mut Term) -> Result<()> { } pub fn start( - conn: &Connection, + conn: &mut Connection, term: &mut Term, + deck_path: &str, deck_name: &str, + mut deck_last_sync: u64, hide_remaining: bool, ) -> Result<()> { loop { - let now = time::seconds_since_unix_epoch()?; + // Synchronize deck if necessary + let deck_last_update = + time::seconds_since_unix_epoch_of(fs::metadata(deck_path)?.modified()?)?; + if deck_last_update > deck_last_sync { + sync::run(conn, deck_path)?; + deck_last_sync = time::seconds_since_unix_epoch()?; + } + let title = title( deck_name, db::count_available(conn).unwrap_or(0), @@ -54,6 +65,7 @@ pub fn start( None => { let message = match db::next_ready(conn) { Some(ready) => { + let now = time::seconds_since_unix_epoch()?; let duration = time::pp_duration(ready - now); format!("Prochaine carte disponible dans {duration}.") } |