From 582344ad48ea0ca77092711369f0b0b6bc730d62 Mon Sep 17 00:00:00 2001 From: lashman Date: Sat, 28 Feb 2026 00:46:39 +0200 Subject: [PATCH] Fix catalog refresh: handle null fields in AppImageHub feed JSON The AppImageHub feed.json contains null values where arrays/strings are expected (296 items with null links, 6 items with null inside categories arrays). Changed AppImageHubItem deserialization to use Option types and flatten nulls. Also fixed refresh handler to dynamically look up the catalog source from DB instead of hardcoding id. --- src/core/catalog.rs | 12 ++++++------ src/ui/catalog_view.rs | 17 ++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/core/catalog.rs b/src/core/catalog.rs index 993a11b..ea2d9c4 100644 --- a/src/core/catalog.rs +++ b/src/core/catalog.rs @@ -152,17 +152,17 @@ fn fetch_appimage_hub() -> Result, CatalogError> { let apps: Vec = feed.items.into_iter().filter_map(|item| { // AppImageHub items need at least a name and a link let name = item.name?; - let download_url = item.links.into_iter() + let download_url = item.links.unwrap_or_default().into_iter() .find(|l| l.r#type == "Download") .map(|l| l.url)?; Some(CatalogApp { name, description: item.description, - categories: item.categories.unwrap_or_default(), + categories: item.categories.unwrap_or_default().into_iter().flatten().collect(), latest_version: None, download_url, - icon_url: item.icons.and_then(|icons| icons.into_iter().next()), + icon_url: item.icons.and_then(|icons| icons.into_iter().flatten().next()), homepage: item.authors.and_then(|a| { let first = a.into_iter().next()?; if let Some(ref author_name) = first.name { @@ -237,10 +237,10 @@ struct AppImageHubFeed { struct AppImageHubItem { name: Option, description: Option, - categories: Option>, + categories: Option>>, authors: Option>, - links: Vec, - icons: Option>, + links: Option>, + icons: Option>>, } #[derive(Debug, serde::Deserialize)] diff --git a/src/ui/catalog_view.rs b/src/ui/catalog_view.rs index 009f5e7..66ef369 100644 --- a/src/ui/catalog_view.rs +++ b/src/ui/catalog_view.rs @@ -175,15 +175,14 @@ pub fn build_catalog_page(db: &Rc) -> adw::NavigationPage { let db_bg = Database::open().ok(); let result = gio::spawn_blocking(move || { if let Some(ref db) = db_bg { - catalog::sync_catalog(db, &catalog::CatalogSource { - id: Some(1), - name: "AppImageHub".to_string(), - url: "https://appimage.github.io/feed.json".to_string(), - source_type: catalog::CatalogType::AppImageHub, - enabled: true, - last_synced: None, - app_count: 0, - }).map_err(|e| e.to_string()) + catalog::ensure_default_sources(db); + let sources = catalog::get_sources(db); + if let Some(source) = sources.first() { + catalog::sync_catalog(db, source) + .map_err(|e| e.to_string()) + } else { + Err("No catalog sources configured".to_string()) + } } else { Err("Failed to open database".to_string()) }