Add background update checks with configurable interval
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user