chromedriver_update/
constant.rs

1use std::sync::LazyLock;
2
3/// Chrome driver path.
4/// Default:
5/// - macos:    "/usr/local/bin"
6/// - linux:    "/usr/bin"
7/// - windows:  ""
8pub static CHROME_DRIVER_PATH: LazyLock<String> = LazyLock::new(|| {
9    let prefix = match std::env::consts::OS {
10        "macos" => "/usr/local/bin",
11        "linux" => "/usr/bin",
12        "windows" => "",
13        _ => "",
14    };
15
16    if !prefix.eq("") {
17        format!("{}/{}", prefix, DRIVERNAME).to_string()
18    } else {
19        "".to_string()
20    }
21});
22
23/// Chrome browser path.
24/// Default:
25/// - macos:    "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
26/// - linux:    "/usr/bin/google-chrome"
27/// - windows:  ""
28pub static CHROME_BROWSER_PATH: LazyLock<String> = LazyLock::new(|| {
29    match std::env::consts::OS {
30        "macos" => "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
31        "linux" => "/usr/bin/google-chrome",
32        "windows" => "",
33        _ => "",
34    }
35    .to_string()
36});
37
38/// Request connect timeout (ms). Default: 5000
39pub static CONNECT_TIMEOUT: u64 = 5000;
40
41/// Request timeout (ms). Default: 10000
42pub static TIMEOUT: u64 = 10000;
43
44static OS: LazyLock<String> = LazyLock::new(|| {
45    match (std::env::consts::OS, std::env::consts::ARCH) {
46        ("macos", "x86_64") => "mac-x64",
47        ("macos", "aarch64") => "mac-arm64",
48        ("windows", "x86") => "win32",
49        ("windows", "x86_64") => "win64",
50        ("linux", "x86_64") => "linux64",
51        _ => "",
52    }
53    .to_string()
54});
55
56static DRIVERNAME: &str = "chromedriver";
57
58// chromedriver-mac-x64
59static FILENAME: LazyLock<String> = LazyLock::new(|| format!("{}-{}", DRIVERNAME, OS.as_str()));
60
61/// Driver path inside downloaded zip file
62/// - unix:      chromedriver-mac-x64/chromedriver
63/// - windows:   chromedriver-win64/chromedriver.exe
64pub static DRIVER_FILE: LazyLock<String> = LazyLock::new(|| {
65    #[cfg(unix)]
66    {
67        return format!("{}/{}", FILENAME.as_str(), DRIVERNAME);
68    }
69
70    #[cfg(windows)]
71    {
72        return format!("{}/{}.exe", FILENAME.as_str(), DRIVERNAME);
73    }
74});
75
76/// Zip file path, composed of the operating system type and the file name
77/// for example: mac-x64/chromedriver-mac-x64.zip
78pub static ZIP_PATH: LazyLock<String> =
79    LazyLock::new(|| format!("{}/{}.zip", OS.as_str(), FILENAME.as_str()));