Add the ability to list installed flatpaks

This commit is contained in:
teackot
2023-05-16 14:28:20 +03:00
parent 26352160be
commit 3f239795b7
@@ -1,10 +1,8 @@
use std::collections::HashSet;
use std::fs::read_to_string;
use std::path::PathBuf;
use std::process::Command;
use std::process::ExitStatus;
use anyhow::{Context, Result};
use serde_json::Value;
use crate::backend::backend_trait::{Backend, Switches, Text};
use crate::{impl_backend_constants, Group, Package};
@@ -20,7 +18,7 @@ const SECTION: Text = "flatpak";
const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_INFO: Switches = &[];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[];
const SWITCHES_NOCONFIRM: Switches = &[];
const SWITCHES_NOCONFIRM: Switches = &["--assumeyes"];
const SWITCHES_REMOVE: Switches = &["uninstall"];
const SUPPORTS_AS_DEPENDENCY: bool = false;
@@ -29,11 +27,11 @@ impl Backend for Flatpak {
impl_backend_constants!();
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
Ok(HashSet::new())
Flatpak::get_installed_packages(true)
}
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
Ok(HashSet::new())
Flatpak::get_installed_packages(false)
}
fn make_dependency(&self, _: &[Package]) -> Result<ExitStatus> {
@@ -47,4 +45,20 @@ impl Flatpak {
packages: HashSet::new(),
}
}
fn get_installed_packages(include_implicit: bool) -> Result<HashSet<Package>> {
let mut cmd = Command::new(BINARY);
cmd.args(&["list", "--columns=application"]);
if !include_implicit {
cmd.arg("--app");
}
let output = String::from_utf8(cmd.output()?.stdout)?;
Ok(
output.lines()
.skip(1)
.map(|pkg| Package::from(pkg))
.collect::<HashSet<Package>>()
)
}
}