diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-08-02 02:43:39 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-08-02 02:43:39 +0200 |
commit | 3362cd9b55021c1325fc573a90ee0be22497bdeb (patch) | |
tree | 0aa139cd452fcb8d9f6bc9c6baac21e852b09f52 /src-tauri/src/northstar/mod.rs | |
parent | e5a74818e79e78d0e065d9375f38fd17a3a591a9 (diff) | |
parent | edbce33c4a8f142967df868fb99476400f4ddfb3 (diff) | |
download | FlightCore-3362cd9b55021c1325fc573a90ee0be22497bdeb.tar.gz FlightCore-3362cd9b55021c1325fc573a90ee0be22497bdeb.zip |
Merge branch 'main' into chore/bump-upload-artifact-action
Diffstat (limited to 'src-tauri/src/northstar/mod.rs')
-rw-r--r-- | src-tauri/src/northstar/mod.rs | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index ea4f4cde..4b16f701 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -4,13 +4,18 @@ pub mod install; pub mod profile; use crate::util::check_ea_app_or_origin_running; -use crate::{ - constants::{CORE_MODS, TITANFALL2_STEAM_ID}, - platform_specific::get_host_os, - GameInstall, InstallType, -}; +use crate::{constants::CORE_MODS, platform_specific::get_host_os, GameInstall, InstallType}; use crate::{NorthstarThunderstoreRelease, NorthstarThunderstoreReleaseWrapper}; use anyhow::anyhow; +use serde::{Deserialize, Serialize}; +use ts_rs::TS; + +#[derive(Serialize, Deserialize, Debug, Clone, TS)] +#[ts(export)] +pub struct NorthstarLaunchOptions { + launch_via_steam: bool, + bypass_checks: bool, +} /// Gets list of available Northstar versions from Thunderstore #[tauri::command] @@ -154,14 +159,12 @@ pub fn get_northstar_version_number(game_install: GameInstall) -> Result<String, #[tauri::command] pub fn launch_northstar( game_install: GameInstall, - launch_via_steam: Option<bool>, - bypass_checks: Option<bool>, + launch_options: NorthstarLaunchOptions, ) -> Result<String, String> { dbg!(game_install.clone()); - let launch_via_steam = launch_via_steam.unwrap_or(false); - if launch_via_steam { - return launch_northstar_steam(game_install, bypass_checks); + if launch_options.launch_via_steam { + return launch_northstar_steam(game_install); } let host_os = get_host_os(); @@ -176,13 +179,11 @@ pub fn launch_northstar( )); } - return launch_northstar_steam(game_install, bypass_checks); + return launch_northstar_steam(game_install); } - let bypass_checks = bypass_checks.unwrap_or(false); - // Only check guards if bypassing checks is not enabled - if !bypass_checks { + if !launch_options.bypass_checks { // Some safety checks before, should have more in the future if get_northstar_version_number(game_install.clone()).is_err() { return Err(anyhow!("Not all checks were met").to_string()); @@ -228,29 +229,31 @@ pub fn launch_northstar( } /// Prepare Northstar and Launch through Steam using the Browser Protocol -pub fn launch_northstar_steam( - game_install: GameInstall, - _bypass_checks: Option<bool>, -) -> Result<String, String> { +pub fn launch_northstar_steam(game_install: GameInstall) -> Result<String, String> { if !matches!(game_install.install_type, InstallType::STEAM) { return Err("Titanfall2 was not installed via Steam".to_string()); } match steamlocate::SteamDir::locate() { - Some(mut steamdir) => { + Ok(steamdir) => { if get_host_os() != "windows" { - let titanfall2_steamid: u32 = TITANFALL2_STEAM_ID.parse().unwrap(); - match steamdir.compat_tool(&titanfall2_steamid) { - Some(_) => {} - None => { - return Err( - "Titanfall2 was not configured to use a compatibility tool".to_string() - ); + match steamdir.compat_tool_mapping() { + Ok(map) => match map.get(&thermite::TITANFALL2_STEAM_ID) { + Some(_) => {} + None => { + return Err( + "Titanfall2 was not configured to use a compatibility tool" + .to_string(), + ); + } + }, + Err(_) => { + return Err("Could not get compatibility tool mapping".to_string()); } } } } - None => { + Err(_) => { return Err("Couldn't access Titanfall2 directory".to_string()); } } @@ -263,7 +266,8 @@ pub fn launch_northstar_steam( match open::that(format!( "steam://run/{}//-profile={} --northstar/", - TITANFALL2_STEAM_ID, game_install.profile + thermite::TITANFALL2_STEAM_ID, + game_install.profile )) { Ok(()) => Ok("Started game".to_string()), Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()), |