Add background update checks with configurable interval

Schedule automatic update checks on startup based on elapsed time
since last check. Add interval SpinRow to preferences and show
'Last checked' timestamp on the dashboard updates section.
This commit is contained in:
lashman
2026-02-27 23:52:28 +02:00
parent c50b61fc83
commit c311fb27c3
4 changed files with 89 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
use adw::prelude::*;
use gtk::gio;
use std::rc::Rc;
use crate::config::APP_ID;
use crate::core::database::Database;
use crate::core::duplicates;
use crate::core::fuse;
@@ -267,6 +269,32 @@ fn build_updates_summary_group(db: &Rc<Database>) -> adw::PreferencesGroup {
updates_row.add_suffix(&updates_arrow);
group.add(&updates_row);
// Last checked timestamp
let settings = gio::Settings::new(APP_ID);
let last_check = settings.string("last-update-check");
let last_label = if last_check.is_empty() {
"Never".to_string()
} else if let Ok(ts) = chrono::NaiveDateTime::parse_from_str(last_check.as_str(), "%Y-%m-%d %H:%M:%S") {
let now = chrono::Utc::now().naive_utc();
let elapsed = now.signed_duration_since(ts);
if elapsed.num_minutes() < 1 {
"Just now".to_string()
} else if elapsed.num_hours() < 1 {
format!("{}m ago", elapsed.num_minutes())
} else if elapsed.num_hours() < 24 {
format!("{}h ago", elapsed.num_hours())
} else {
format!("{}d ago", elapsed.num_days())
}
} else {
"Unknown".to_string()
};
let last_row = adw::ActionRow::builder()
.title("Last checked")
.subtitle(&last_label)
.build();
group.add(&last_row);
group
}