i3status_rs/blocks/packages/
flatpak.rs

1use tokio::process::Command;
2
3use super::*;
4
5#[derive(Default)]
6pub struct Flatpak;
7
8impl Flatpak {
9    pub fn new() -> Self {
10        Default::default()
11    }
12}
13
14#[async_trait]
15impl Backend for Flatpak {
16    fn name(&self) -> Cow<'static, str> {
17        "flatpak".into()
18    }
19
20    async fn get_updates_list(&self) -> Result<Vec<String>> {
21        Command::new("flatpak")
22            .env("LC_ALL", "C")
23            .args(["update", "--appstream", "-y"])
24            .output()
25            .await
26            .error("Failed to run `flatpak update`")?;
27
28        let stdout = Command::new("flatpak")
29            .env("LC_ALL", "C")
30            .args(["remote-ls", "--updates", "--columns=ref"])
31            .output()
32            .await
33            .error("Failed to run `flatpak remote-ls`")?
34            .stdout;
35
36        let updates = String::from_utf8(stdout)
37            .error("flatpak produced non-UTF8 output")?
38            .lines()
39            .filter_map(|line| (line.len() > 1).then_some(line.to_string()))
40            .collect();
41
42        Ok(updates)
43    }
44}