From 8a6810fe089f78c01b3fe6eee78d4115ffc7eb70 Mon Sep 17 00:00:00 2001 From: Victor Fuentes Date: Thu, 29 Sep 2022 03:20:04 -0400 Subject: [PATCH] Fix profile package listing --- flake.nix | 2 +- src/parse/packages.rs | 9 +++++++-- src/ui/window.rs | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index e3169c3..2fdf9ff 100644 --- a/flake.nix +++ b/flake.nix @@ -64,7 +64,7 @@ openssl pandoc pango - pkgconfig + pkg-config polkit wrapGAppsHook4 nixos-appstream-data diff --git a/src/parse/packages.rs b/src/parse/packages.rs index 595c21c..0707a16 100644 --- a/src/parse/packages.rs +++ b/src/parse/packages.rs @@ -158,6 +158,11 @@ pub struct AppScreenshotImage { pub url: String, } +#[derive(Debug, Serialize, Deserialize)] +struct FlakePkgs { + packages: HashMap +} + #[derive(Debug, Serialize, Deserialize)] struct FlakeJson { pname: IString, @@ -236,7 +241,7 @@ pub fn readprofilepkgs() -> Result, Box = simd_json::serde::from_reader(reader)?; - let profilepkgs = profilepkgs.into_iter().filter_map(|(k, v)| if let Some(pkg) = k.strip_prefix("legacyPackages.x86_64-linux.") { Some((pkg.to_string(), v.version.to_string())) } else { None }).collect::>(); + let profilepkgs: FlakePkgs = simd_json::serde::from_reader(reader)?; + let profilepkgs = profilepkgs.packages.into_iter().map(|(pkg, v)| (pkg.to_string(), v.version.to_string())).collect::>(); Ok(profilepkgs) } \ No newline at end of file diff --git a/src/ui/window.rs b/src/ui/window.rs index 36a7060..f12e8ba 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -957,20 +957,20 @@ impl Component for AppModel { .arg("show-derivation") .arg(&storepath) .output()?; - let data: Value = serde_json::from_str(&String::from_utf8_lossy(&output.stdout))?; - if let Some(version) = data.as_object().unwrap().values().next().unwrap()["env"].get("version") { - let version = version.as_str().unwrap().to_string(); - pcurrpkgs.insert( - pkgname.to_string(), - version, - ); - } else { - pcurrpkgs.insert( - pkgname.to_string(), - String::default(), - ); + if let Ok(data) = serde_json::from_str::(&String::from_utf8_lossy(&output.stdout)) { + if let Some(version) = data.as_object().unwrap().values().next().unwrap()["env"].get("version") { + let version = version.as_str().unwrap().to_string(); + pcurrpkgs.insert( + pkgname.to_string(), + version, + ); + } else { + pcurrpkgs.insert( + pkgname.to_string(), + String::default(), + ); + } } - } } }