diff options
-rw-r--r-- | launcher/src/lib.rs | 27 | ||||
-rw-r--r-- | launcher/src/main.rs | 27 |
2 files changed, 28 insertions, 26 deletions
diff --git a/launcher/src/lib.rs b/launcher/src/lib.rs index 9e2ef8b..3e5d0fe 100644 --- a/launcher/src/lib.rs +++ b/launcher/src/lib.rs @@ -1,3 +1,5 @@ +mod constants; + use std::ffi::OsStr; use std::path::PathBuf; @@ -13,4 +15,29 @@ impl AppData { 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 + } } diff --git a/launcher/src/main.rs b/launcher/src/main.rs index bf11997..6fb8bc8 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -39,7 +39,7 @@ fn main() { work_dir.to_str().unwrap() ); - let app_data = locate_app(&work_dir); + let app_data = AppData::locate_app(&work_dir); let runtime_path = locate_runtime(); launch_app(runtime_path, app_data) } @@ -52,31 +52,6 @@ fn get_working_directory() -> PathBuf { .to_owned() } -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 -} - fn locate_runtime() -> Option<PathBuf> { let runtime_search_paths = search_path::get_search_paths(); let runtime_search_paths_string = runtime_search_paths |