From 4457cdfa66fe55a81f23e812820d3774c3d74230 Mon Sep 17 00:00:00 2001 From: innocentzero Date: Sat, 2 Nov 2024 14:57:20 +0530 Subject: [PATCH] Manage pinned flatpak runtimes This patch series attempts to add support to manage the pinned runtimes of flatpak. Signed-off-by: innocentzero --- src/backends/flatpak.rs | 53 ++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/backends/flatpak.rs b/src/backends/flatpak.rs index cbb1142..234856d 100644 --- a/src/backends/flatpak.rs +++ b/src/backends/flatpak.rs @@ -33,7 +33,7 @@ impl Backend for Flatpak { return Ok(BTreeMap::new()); } - let sys_explicit_btree = run_command_for_stdout( + let sys_explicit_out = run_command_for_stdout( [ "flatpak", "list", @@ -42,12 +42,12 @@ impl Backend for Flatpak { "--columns=application", ], Perms::Same, - )? - .lines() - .map(String::from) - .collect::>(); + )?; + let sys_explicit = sys_explicit_out + .lines() + .map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: true })); - let user_explicit_btree = run_command_for_stdout( + let user_explicit_out = run_command_for_stdout( [ "flatpak", "list", @@ -56,19 +56,34 @@ impl Backend for Flatpak { "--columns=application", ], Perms::Same, - )? - .lines() - .map(String::from) - .collect::>(); - - let sys_explicit = sys_explicit_btree - .iter() - .map(|x| (x.clone(), FlatpakQueryInfo { systemwide: true })); - let user_explicit = user_explicit_btree - .iter() - .map(|x| (x.clone(), FlatpakQueryInfo { systemwide: false })); - - let all = sys_explicit.chain(user_explicit).collect(); + )?; + let user_explicit = user_explicit_out + .lines() + .map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: false })); + + let sys_explicit_runtimes_out = + run_command_for_stdout(["flatpak", "pin", "--system"], Perms::Same)?; + let sys_explicit_runtimes = sys_explicit_runtimes_out.lines().skip(1).map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: true }, + ) + }); + + let user_explicit_runtimes_out = + run_command_for_stdout(["flatpak", "pin", "--user"], Perms::Same)?; + let user_explicit_runtimes = user_explicit_runtimes_out.lines().skip(1).map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: false }, + ) + }); + + let all = sys_explicit + .chain(user_explicit) + .chain(sys_explicit_runtimes) + .chain(user_explicit_runtimes) + .collect(); Ok(all) }