1
use cli_prompts_rs::CliPrompt;
2
use owo_colors::OwoColorize;
3

            
4
use crate::{config::Config, utils::service::register};
5

            
6
pub async fn command() -> Result<(), String> {
7
    println!("{}", "~ Protontweaks Setup ~".blue().bold());
8

            
9
    let mut cli_prompt = CliPrompt::new();
10

            
11
    let service = if os_info::get().to_string().contains("NixOS") {
12
        println!(
13
            "{} {}",
14
            "[service] ->",
15
            "skipping due to read only file system...".italic()
16
        );
17
        false
18
    } else {
19
        cli_prompt
20
            .prompt_confirm("Would you like to install the watch service?")
21
            .map_err(|e| e.to_string())?
22
    };
23

            
24
    if service {
25
        println!("{}", "Registering service...".bold());
26
        register().await?;
27
        println!("{}", "Service registered successfully!".green());
28
    }
29

            
30
    let config = cli_prompt
31
        .prompt_confirm("Would you like us to initialize a config for you?")
32
        .map_err(|e| e.to_string())?;
33

            
34
    if config {
35
        let gamemode = cli_prompt
36
            .prompt_confirm(
37
                "Would you like us to automatically run gamemode on any games that support it?",
38
            )
39
            .map_err(|e| e.to_string())?;
40

            
41
        let mangohud = cli_prompt
42
            .prompt_confirm(
43
                "Would you like us to automatically run mangohud on any games that support it?",
44
            )
45
            .map_err(|e| e.to_string())?;
46

            
47
        let home = Config::discover_valid_home()?;
48

            
49
        let mut config = Config::default();
50
        config.gamemode = gamemode;
51
        config.mangohud = mangohud;
52

            
53
        config.save_at(&home)?;
54
        cli_prompt
55
            .print_note(format!("Config saved to '{home}'!").as_str())
56
            .map_err(|e| e.to_string())?;
57
    }
58

            
59
    cli_prompt
60
        .outro(format!("Protontweaks setup successfully!").as_str())
61
        .map_err(|e| e.to_string())?;
62

            
63
    Ok(())
64
}