Show update count badge on Updates tab in ViewSwitcherBar
Add updatable_count() database method and refresh_update_badge() window method. The Updates tab now shows a numeric badge with the number of available updates and highlights with needs_attention.
This commit is contained in:
@@ -1257,6 +1257,16 @@ impl Database {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn updatable_count(&self) -> i64 {
|
||||||
|
self.conn
|
||||||
|
.query_row(
|
||||||
|
"SELECT COUNT(*) FROM appimages WHERE latest_version IS NOT NULL",
|
||||||
|
[],
|
||||||
|
|row| row.get(0),
|
||||||
|
)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_appimages_with_updates(&self) -> SqlResult<Vec<AppImageRecord>> {
|
pub fn get_appimages_with_updates(&self) -> SqlResult<Vec<AppImageRecord>> {
|
||||||
let sql = format!(
|
let sql = format!(
|
||||||
"SELECT {} FROM appimages WHERE latest_version IS NOT NULL
|
"SELECT {} FROM appimages WHERE latest_version IS NOT NULL
|
||||||
|
|||||||
@@ -1114,6 +1114,9 @@ impl DriftwoodWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update badge on Updates tab
|
||||||
|
self.refresh_update_badge();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trigger_scan(&self) {
|
fn trigger_scan(&self) {
|
||||||
@@ -1317,6 +1320,19 @@ impl DriftwoodWindow {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the badge number on the Updates tab in the ViewSwitcherBar.
|
||||||
|
fn refresh_update_badge(&self) {
|
||||||
|
let db = self.database();
|
||||||
|
let count = db.updatable_count();
|
||||||
|
if let Some(view_stack) = self.imp().view_stack.get() {
|
||||||
|
if let Some(child) = view_stack.child_by_name("updates") {
|
||||||
|
let page = view_stack.page(&child);
|
||||||
|
page.set_badge_number(count as u32);
|
||||||
|
page.set_needs_attention(count > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn start_file_watcher(&self) {
|
fn start_file_watcher(&self) {
|
||||||
let settings = self.settings();
|
let settings = self.settings();
|
||||||
let dirs: Vec<std::path::PathBuf> = settings
|
let dirs: Vec<std::path::PathBuf> = settings
|
||||||
|
|||||||
Reference in New Issue
Block a user