From 77472e57d0ce3f7e6420017225b3bdfbe1ac9050 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Fri, 10 May 2024 22:26:44 +0200 Subject: Crappy code fix 11/? --- launcher/src/main.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'launcher/src') diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 73b6862..4a87c81 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1,6 +1,21 @@ +use std::ffi::OsStr; use std::path::PathBuf; use std::process; +enum AppData { + Folder(PathBuf), + Asar(PathBuf) +} + +impl AppData { + fn get_path(&self) -> &OsStr { + match self { + AppData::Folder(path) => path.as_ref(), + AppData::Asar(path) => path.as_ref() + } + } +} + fn get_home() -> PathBuf { dirs::home_dir().unwrap_or(PathBuf::from("/")) } @@ -146,8 +161,7 @@ fn main() { work_dir.to_str().unwrap() ); - let mut found_app = false; - let mut app_is_asar = false; + let mut app_data: Option = None; let mut app_path_folder = PathBuf::from(work_dir); app_path_folder.push(APP_FOLDER_PATH); @@ -156,10 +170,9 @@ fn main() { app_path_asar.push(APP_ASAR_PATH); if app_path_folder.exists() { - found_app = true; + app_data = Some(AppData::Folder(app_path_folder)) } else if app_path_asar.exists() { - found_app = true; - app_is_asar = true; + app_data = Some(AppData::Asar(app_path_asar)) } else { println!( "atomic-launcher: Warning: Could not find Electron-compatible app.\ @@ -190,16 +203,12 @@ fn main() { "atomic-launcher: Found atomic-runtime at {}", path.to_str().unwrap() ); - let mut cmd = process::Command::new(path) - .env("ATOMIC_LAUNCHER_VERSION", VERSION); + let mut cmd = process::Command::new(path); + cmd.env("ATOMIC_LAUNCHER_VERSION", VERSION); println!("atomic-launcher: Executing: {:?}", cmd); - if found_app { - cmd.arg(if app_is_asar { - app_path_asar - } else { - app_path_folder - }) + if let Some(app_data) = app_data { + cmd.arg(app_data.get_path()); } if let Ok(status) = cmd.status() { -- cgit