1
use regex::Regex;
2

            
3
use crate::utils::commands::CLI;
4

            
5
use super::Protontricks;
6

            
7
impl Protontricks {
8
    pub async fn try_apps() -> Result<Vec<String>, String> {
9
        let output = Protontricks::exec(["--list"]).await?;
10

            
11
        let re = Regex::new(r"(?m)^(?<name>[\w\s]+)\s\((?<app_id>\d+)\)$").unwrap();
12

            
13
        let mut results = vec![];
14

            
15
        for caps in re.captures_iter(&output) {
16
            results.push(caps["app_id"].to_string());
17
        }
18

            
19
        Ok(results)
20
    }
21

            
22
    pub async fn apps() -> Vec<String> {
23
        Self::try_apps().await.unwrap()
24
    }
25

            
26
    /// Lists all the installed verbs
27
    pub async fn installed(app_id: &str) -> Vec<String> {
28
        let Ok(output) = Protontricks::exec([app_id, "list-installed"]).await else {
29
            return vec![];
30
        };
31

            
32
        let re = Regex::new(r"(?m)^(?<name>(?:[^-]{2})[-\w]+)$").unwrap();
33

            
34
        let mut results = vec![];
35

            
36
        for caps in re.captures_iter(&output) {
37
            results.push(caps["name"].to_string())
38
        }
39

            
40
        results
41
    }
42
}