1
use protontweaks_api::app::App;
2

            
3
use crate::utils::commands::protontricks::Protontricks;
4

            
5
/// Applies the app and returns a result of whether it was successful
6
pub async fn try_apply(app: &App) -> Result<(u32, u32), String> {
7
    let tweaks = app.flatten().await;
8
    trace!("App ID: {}; Name: {}", app.id, app.name);
9

            
10
    if tweaks.tricks.len() == 0 {
11
        warn!("No tricks were found for {} -> {}", app.id, app.name);
12
        return Ok((0, 0));
13
    }
14

            
15
    trace!("Installing tricks for {} -> {}", app.id, app.name);
16
    let tweaks_applied = Protontricks::install_components(&app.id, &tweaks.tricks).await?;
17

            
18
    return Ok((tweaks_applied, tweaks.tricks.len().try_into().unwrap()));
19
}
20

            
21
/// Applies the app and panics if a failure occurs.
22
pub async fn apply(app: &App) -> (u32, u32) {
23
    return try_apply(app).await.unwrap();
24
}
25

            
26
/// Applies the app, if an error occurs it simply logs it and returns that no tweaks were applied
27
pub async fn apply_safe(app: &App) -> (u32, u32) {
28
    match try_apply(app).await {
29
        Ok(result) => result,
30
        Err(e) => {
31
            error!("{e}");
32
            (0, app.tweaks.tricks.len().try_into().unwrap())
33
        }
34
    }
35
}