From 2a6714bb00afebe50ce92ed726a50e11c0874966 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Fri, 10 May 2024 22:59:19 +0200 Subject: Crappy code fix 14/? --- launcher/src/lib.rs | 24 ++++++++++-------------- 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 { - let mut app_data: Option = None; - + pub fn locate_app(work_dir: &PathBuf) -> Result { 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 { .next() } -fn launch_app(runtime_path: Option, app_data: Option) { +fn launch_app(runtime_path: Option, app_data: Result) { if let Some(path) = runtime_path { println!( "atomic-launcher: Found atomic-runtime at {}", @@ -80,8 +79,18 @@ fn launch_app(runtime_path: Option, app_data: Option) { 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() { -- cgit