diff --git a/src-tauri/src/sessions/sessions.rs b/src-tauri/src/sessions/sessions.rs index 2edd30271..e7ffff419 100644 --- a/src-tauri/src/sessions/sessions.rs +++ b/src-tauri/src/sessions/sessions.rs @@ -10,7 +10,7 @@ use std::{ io::{BufReader, Read}, os::unix::prelude::MetadataExt, path::Path, - time::SystemTime, + time, }; use uuid::Uuid; @@ -105,8 +105,8 @@ impl Session { } pub fn from_head(repo: &git2::Repository, project: &projects::Project) -> Result { - let now_ts = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) + let now_ts = time::SystemTime::now() + .duration_since(time::UNIX_EPOCH) .unwrap() .as_millis(); @@ -202,7 +202,7 @@ impl Session { }) } - pub fn update(&self, project: &projects::Project) -> Result<()> { + pub fn update(&mut self, project: &projects::Project) -> Result<()> { update(project, self) } @@ -277,7 +277,12 @@ fn write(session_path: &Path, session: &Session) -> Result<()> { Ok(()) } -fn update(project: &projects::Project, session: &Session) -> Result<()> { +fn update(project: &projects::Project, session: &mut Session) -> Result<()> { + session.meta.last_timestamp_ms = time::SystemTime::now() + .duration_since(time::UNIX_EPOCH) + .unwrap() + .as_millis(); + let session_path = project.session_path(); log::debug!("{}: Updating current session", session_path.display()); if session_path.exists() { @@ -453,6 +458,10 @@ fn flush( )); } + session + .update(project) + .with_context(|| format!("failed to update session"))?; + let wd_index = &mut git2::Index::new() .with_context(|| format!("failed to create index for working directory"))?; build_wd_index(&repo, wd_index).with_context(|| format!("failed to build wd index"))?; diff --git a/src-tauri/src/watchers/delta.rs b/src-tauri/src/watchers/delta.rs index bb59dfaf6..22777f59f 100644 --- a/src-tauri/src/watchers/delta.rs +++ b/src-tauri/src/watchers/delta.rs @@ -8,7 +8,6 @@ use std::fs; use std::path::Path; use std::sync::mpsc::channel; use std::thread; -use std::time::SystemTime; use std::{collections::HashMap, sync::Mutex}; #[derive(Default)] @@ -234,11 +233,6 @@ fn write_beginning_meta_files( .map_err(|e| format!("Error while getting current session: {}", e.to_string()))? { Some(mut session) => { - let now_ts = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_millis(); - session.meta.last_timestamp_ms = now_ts; session .update(project) .with_context(|| "failed to update session")?; diff --git a/src-tauri/src/watchers/git.rs b/src-tauri/src/watchers/git.rs index 72e824474..f62e5782c 100644 --- a/src-tauri/src/watchers/git.rs +++ b/src-tauri/src/watchers/git.rs @@ -129,7 +129,6 @@ fn session_to_commit( let elapsed_last = now - current_session.meta.last_timestamp_ms; let elapsed_start = now - current_session.meta.start_timestamp_ms; - // TODO: uncomment if (elapsed_last > FIVE_MINUTES) || (elapsed_start > ONE_HOUR) { Ok(Some(current_session)) } else {