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

@@ -961,6 +961,37 @@ impl DriftwoodWindow {
});
}
// Scheduled background update check
let settings_upd = self.settings().clone();
if settings_upd.boolean("auto-check-updates") {
let last_check = settings_upd.string("last-update-check").to_string();
let interval_hours = settings_upd.int("update-check-interval-hours") as i64;
let should_check = if last_check.is_empty() {
true
} else if let Ok(last) = chrono::NaiveDateTime::parse_from_str(&last_check, "%Y-%m-%d %H:%M:%S") {
let now = chrono::Utc::now().naive_utc();
let elapsed = now.signed_duration_since(last);
elapsed.num_hours() >= interval_hours
} else {
true
};
if should_check {
let settings_save = settings_upd.clone();
glib::spawn_future_local(async move {
let result = gio::spawn_blocking(move || {
let bg_db = Database::open().expect("DB open failed");
update_dialog::batch_check_updates(&bg_db)
})
.await;
if let Ok(count) = result {
log::info!("Background update check: {} updates available", count);
}
let now = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S").to_string();
settings_save.set_string("last-update-check", &now).ok();
});
}
}
// Check for orphaned desktop entries in the background
let toast_overlay = self.imp().toast_overlay.get().unwrap().clone();
glib::spawn_future_local(async move {