diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-05-10 22:59:19 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-05-10 22:59:19 +0200 |
commit | 2a6714bb00afebe50ce92ed726a50e11c0874966 (patch) | |
tree | a3ab548c1db093da83d1db4f01c73610c4d85a7f /launcher/src | |
parent | d56b6536f95ef928bcb0c690280887d976c60b9b (diff) | |
download | atomic-2a6714bb00afebe50ce92ed726a50e11c0874966.tar.gz atomic-2a6714bb00afebe50ce92ed726a50e11c0874966.tar.bz2 atomic-2a6714bb00afebe50ce92ed726a50e11c0874966.zip |
Crappy code fix 14/?
Diffstat (limited to 'launcher/src')
-rw-r--r-- | launcher/src/lib.rs | 24 | ||||
-rw-r--r-- | launcher/src/main.rs | 19 |
2 files changed, 24 insertions, 19 deletions
diff --git a/launcher/src/lib.rs b/launcher/src/lib.rs index 3e5d0fe..32ae8ee 100644 --- a/launcher/src/lib.rs +++ b/launcher/src/lib.rs @@ -1,13 +1,18 @@ -mod constants; +pub mod constants; use std::ffi::OsStr; use std::path::PathBuf; +use crate::AppDataError::NotFound; pub enum AppData { Folder(PathBuf), Asar(PathBuf) } +pub enum AppDataError { + NotFound(PathBuf, PathBuf) +} + impl AppData { pub fn get_path(&self) -> &OsStr { match self { @@ -16,9 +21,7 @@ impl AppData { } } - pub fn locate_app(work_dir: &PathBuf) -> Option<AppData> { - let mut app_data: Option<AppData> = None; - + pub fn locate_app(work_dir: &PathBuf) -> Result<AppData, AppDataError> { let mut app_path_folder = PathBuf::from(work_dir); app_path_folder.push(constants::APP_FOLDER_PATH); @@ -26,18 +29,11 @@ impl AppData { app_path_asar.push(constants::APP_ASAR_PATH); if app_path_folder.exists() { - app_data = Some(AppData::Folder(app_path_folder)) + Ok(AppData::Folder(app_path_folder)) } else if app_path_asar.exists() { - app_data = Some(AppData::Asar(app_path_asar)) + Ok(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() - ); + Err(NotFound(app_path_folder, app_path_asar)) } - - app_data } } diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 6fb8bc8..4e61592 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1,9 +1,8 @@ mod search_path; -mod constants; use std::path::PathBuf; use std::process; -use launcher::AppData; +use launcher::{AppData, AppDataError, constants}; fn show_system_info() { println!( @@ -70,7 +69,7 @@ fn locate_runtime() -> Option<PathBuf> { .next() } -fn launch_app(runtime_path: Option<PathBuf>, app_data: Option<AppData>) { +fn launch_app(runtime_path: Option<PathBuf>, app_data: Result<AppData, AppDataError>) { if let Some(path) = runtime_path { println!( "atomic-launcher: Found atomic-runtime at {}", @@ -80,8 +79,18 @@ fn launch_app(runtime_path: Option<PathBuf>, app_data: Option<AppData>) { cmd.env("ATOMIC_LAUNCHER_VERSION", constants::VERSION); println!("atomic-launcher: Executing: {:?}", cmd); - if let Some(app_data) = app_data { - cmd.arg(app_data.get_path()); + match app_data { + Ok(app_data) => { + cmd.arg(app_data.get_path()); + } + Err(AppDataError::NotFound(app_path_folder, app_path_asar)) => { + 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() + ); + } } if let Ok(status) = cmd.status() { |