Swadhin Biswas Ci/improve release notes (#41) · 8/28/2026
04d550f
75 lines · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::installer;
use crate::manager;

fn is_appimage_path(arg: &str) -> bool {
    arg.to_ascii_lowercase().ends_with(".appimage")
}

fn is_deb_path(arg: &str) -> bool {
    arg.to_ascii_lowercase().ends_with(".deb")
}

fn is_rpm_path(arg: &str) -> bool {
    arg.to_ascii_lowercase().ends_with(".rpm")
}

fn is_exe_path(arg: &str) -> bool {
    let l = arg.to_ascii_lowercase();
    l.ends_with(".exe") || l.ends_with(".msi")
}

pub async fn handle_cli(path: &str) {
    let owned = path.to_string();
    // Only treat as installer input if the path exists locally; deep-link URIs
    // like linuxy://host/file.deb must not trigger install+exit and should
    // fall through to the GUI-safe path.
    let is_local_file = !path.contains("://") && std::path::Path::new(path).exists();
    let install_result = if is_appimage_path(path) && is_local_file {
        println!("Installing {}...", path);
        Some(installer::install_appimage_internal(owned).await)
    } else if is_deb_path(path) && is_local_file {
        println!("Installing {}...", path);
        Some(installer::install_deb_internal(owned).await)
    } else if is_rpm_path(path) && is_local_file {
        println!("Installing {}...", path);
        Some(installer::install_rpm_internal(owned).await)
    } else if is_exe_path(path) && is_local_file {
        println!("Installing {}...", path);
        Some(installer::install_executable_internal(owned).await)
    } else {
        None
    };

    if let Some(result) = install_result {
        match result {
            Ok(msg) => println!("{}", msg),
            Err(err) => {
                eprintln!("Error: {}", err);
                std::process::exit(1);
            },
        }
        std::process::exit(0);
    } else {
        // Unrecognized argument: only treat as CLI "list" when running in a
        // terminal. Deep links / desktop-file launches that hit this fallback
        // should not terminate the GUI.
        if std::io::IsTerminal::is_terminal(&std::io::stdout()) {
            match manager::get_installed_apps().await {
                Ok(apps) => {
                    println!("{:<30} {:<10} {:<20}", "NAME", "SANDBOX", "PATH");
                    for app in apps {
                        println!("{:<30} {:<10} {:<20}", app.name, app.sandboxed, app.path);
                    }
                },
                Err(e) => eprintln!("Error: {}", e),
            }
            std::process::exit(0);
        } else {
            eprintln!(
                "Unrecognized argument '{}' — ignoring, continuing to GUI",
                path
            );
        }
    }
}