aboutsummaryrefslogtreecommitdiff
path: root/launcher/src/lib.rs
blob: 3e5d0fea3fa974933c6bff815432e690301c185c (plain)
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
mod constants;

use std::ffi::OsStr;
use std::path::PathBuf;

pub enum AppData {
    Folder(PathBuf),
    Asar(PathBuf)
}

impl AppData {
    pub fn get_path(&self) -> &OsStr {
        match self {
            AppData::Folder(path) => path.as_ref(),
            AppData::Asar(path) => path.as_ref()
        }
    }

    pub fn locate_app(work_dir: &PathBuf) -> Option<AppData> {
        let mut app_data: Option<AppData> = None;

        let mut app_path_folder = PathBuf::from(work_dir);
        app_path_folder.push(constants::APP_FOLDER_PATH);

        let mut app_path_asar = PathBuf::from(work_dir);
        app_path_asar.push(constants::APP_ASAR_PATH);

        if app_path_folder.exists() {
            app_data = Some(AppData::Folder(app_path_folder))
        } else if app_path_asar.exists() {
            app_data = Some(AppData::Asar(app_path_asar))
        } else {
            println!(
                "atomic-launcher: Warning: Could not find Electron-compatible app.\
            Looked in {} and {}. The default atomic-runtime application will be opened instead.",
                app_path_folder.to_str().unwrap(),
                app_path_asar.to_str().unwrap()
            );
        }

        app_data
    }
}