use std::path::Path;
use std::time::Instant;
use crate::widgets::markdown_widget::foundation::types::GitStats;
use crate::widgets::markdown_widget::state::git_stats_state::helpers::compute_git_stats;
use crate::widgets::markdown_widget::state::git_stats_state::GitStatsState;
const GIT_STATS_UPDATE_INTERVAL_SECS: u64 = 2;
impl GitStatsState {
pub fn update(&mut self, source_path: Option<&Path>) -> bool {
if !self.show {
return false;
}
let should_update = match self.last_update {
Some(last_update) => last_update.elapsed().as_secs() >= GIT_STATS_UPDATE_INTERVAL_SECS,
None => true, };
if should_update {
let (adds, modified, dels) = compute_git_stats(source_path);
self.cache = Some(GitStats {
additions: adds,
modified,
deletions: dels,
});
self.last_update = Some(Instant::now());
true
} else {
false
}
}
}