From 6003069ebbbfeacae7b9d5adfb88c6ef41821de8 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 03:21:46 +0200 Subject: refactor: Move NS installation logic to module (#619) Move Northstar installation logic to module in order to clean up `main.rs` --- src-tauri/src/main.rs | 54 ++------------------------------------ src-tauri/src/northstar/install.rs | 43 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 32804192..6b0425cd 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -124,8 +124,8 @@ fn main() { check_is_northstar_outdated, verify_install_location, platform_specific::get_host_os, - install_northstar_wrapper, - update_northstar, + northstar::install::install_northstar_wrapper, + northstar::install::update_northstar, northstar::launch_northstar, northstar::launch_northstar_steam, github::release_notes::check_is_flightcore_outdated, @@ -278,56 +278,6 @@ async fn verify_install_location(game_path: String) -> bool { } } -/// Installs Northstar to the given path -#[tauri::command] -async fn install_northstar_wrapper( - window: tauri::Window, - game_install: GameInstall, - northstar_package_name: Option, - version_number: Option, -) -> Result { - log::info!("Running Northstar install"); - - // Get Northstar package name (`Northstar` vs `NorthstarReleaseCandidate`) - let northstar_package_name = northstar_package_name - .map(|name| { - if name.len() <= 1 { - "Northstar".to_string() - } else { - name - } - }) - .unwrap_or("Northstar".to_string()); - - match northstar::install::install_northstar( - window, - game_install, - northstar_package_name, - version_number, - ) - .await - { - Ok(_) => Ok(true), - Err(err) => { - log::error!("{}", err); - Err(err) - } - } -} - -/// Update Northstar install in the given path -#[tauri::command] -async fn update_northstar( - window: tauri::Window, - game_install: GameInstall, - northstar_package_name: Option, -) -> Result { - log::info!("Updating Northstar"); - - // Simply re-run install with up-to-date version for upate - install_northstar_wrapper(window, game_install, northstar_package_name, None).await -} - /// Installs the specified mod #[tauri::command] async fn install_mod_wrapper( diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 757f6c68..693d7af2 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -29,6 +29,49 @@ struct InstallProgress { state: InstallState, } +/// Installs Northstar to the given path +#[tauri::command] +pub async fn install_northstar_wrapper( + window: tauri::Window, + game_install: GameInstall, + northstar_package_name: Option, + version_number: Option, +) -> Result { + log::info!("Running Northstar install"); + + // Get Northstar package name (`Northstar` vs `NorthstarReleaseCandidate`) + let northstar_package_name = northstar_package_name + .map(|name| { + if name.len() <= 1 { + "Northstar".to_string() + } else { + name + } + }) + .unwrap_or("Northstar".to_string()); + + match install_northstar(window, game_install, northstar_package_name, version_number).await { + Ok(_) => Ok(true), + Err(err) => { + log::error!("{}", err); + Err(err) + } + } +} + +/// Update Northstar install in the given path +#[tauri::command] +pub async fn update_northstar( + window: tauri::Window, + game_install: GameInstall, + northstar_package_name: Option, +) -> Result { + log::info!("Updating Northstar"); + + // Simply re-run install with up-to-date version for upate + install_northstar_wrapper(window, game_install, northstar_package_name, None).await +} + /// Copied from `papa` source code and modified ///Install N* from the provided mod /// -- cgit v1.2.3