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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +235,25 @@ fn build_behavior_page(settings: &gio::Settings) -> adw::PreferencesPage {
|
||||
});
|
||||
automation_group.add(&auto_update_row);
|
||||
|
||||
let interval_row = adw::SpinRow::builder()
|
||||
.title(&i18n("Update check interval"))
|
||||
.subtitle(&i18n("Hours between automatic update checks"))
|
||||
.build();
|
||||
let interval_adj = gtk::Adjustment::new(
|
||||
settings.int("update-check-interval-hours") as f64,
|
||||
1.0,
|
||||
168.0,
|
||||
1.0,
|
||||
6.0,
|
||||
0.0,
|
||||
);
|
||||
interval_row.set_adjustment(Some(&interval_adj));
|
||||
let settings_interval = settings.clone();
|
||||
interval_row.connect_value_notify(move |row| {
|
||||
settings_interval.set_int("update-check-interval-hours", row.value() as i32).ok();
|
||||
});
|
||||
automation_group.add(&interval_row);
|
||||
|
||||
let auto_integrate_row = adw::SwitchRow::builder()
|
||||
.title(&i18n("Auto-integrate new AppImages"))
|
||||
.subtitle(&i18n("Automatically add newly discovered AppImages to the desktop menu"))
|
||||
|
||||
Reference in New Issue
Block a user