i3status_rs/blocks/packages/
dnf.rs

1use tokio::process::Command;
2
3use super::super::packages::*;
4
5#[derive(Default)]
6pub struct Dnf;
7
8impl Dnf {
9    pub fn new() -> Self {
10        Default::default()
11    }
12}
13
14#[async_trait]
15impl Backend for Dnf {
16    fn name(&self) -> Cow<'static, str> {
17        "dnf".into()
18    }
19
20    async fn get_updates_list(&self) -> Result<Vec<String>> {
21        let stdout = Command::new("sh")
22            .env("LC_LANG", "C")
23            .args(["-c", "dnf check-update -q --skip-broken"])
24            .output()
25            .await
26            .error("Failed to run dnf check-update")?
27            .stdout;
28        let updates = String::from_utf8(stdout).error("dnf produced non-UTF8 output")?;
29        let updates: Vec<String> = updates
30            .lines()
31            .filter(|line| line.len() > 1)
32            .map(|lines| lines.to_string())
33            .collect();
34
35        Ok(updates)
36    }
37}