aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJoris2023-07-15 10:09:30 +0200
committerJoris2023-07-15 10:09:30 +0200
commit8fb457d5639d11d5075d664001e98148e223f257 (patch)
treefd8b2b1ddcd5fa0756ff8ecabb34f66031e0fc5b /src/gui
parentd68ef3c63c041fcf1844df1fffddbc9c8cf1bfcf (diff)
Re synchronize deck if necessary between cards
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/mod.rs16
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}.")
}