Skip to content

Commit

Permalink
fix: Pass launch options to Steam (#392)
Browse files Browse the repository at this point in the history
Relying on a file to be parsed in time is unreliably, and if the file is open while we delete it we may run into locking problems.
Downside is that this gives a fugly prompt
  • Loading branch information
Jan200101 committed Jul 7, 2023
1 parent e623161 commit 5911c0e
Showing 1 changed file with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ async fn get_available_northstar_versions() -> Result<Vec<NorthstarThunderstoreR
Ok(releases)
}

// The remaining below was originally in `lib.rs`.
// As this was causing issues it was moved into `main.rs` until being later moved into dedicated modules
use std::{fs, path::Path};

use anyhow::Result;

pub mod constants;
Expand Down Expand Up @@ -579,43 +575,8 @@ fn launch_northstar_steam(
return Err("Couldn't access Titanfall2 directory".to_string());
}

let run_northstar = "run_northstar.txt";
let run_northstar_bak = "run_northstar.txt.bak";

if Path::new(run_northstar).exists() {
// rename should ovewrite existing files
fs::rename(run_northstar, run_northstar_bak).unwrap();
}

// Passing arguments gives users a prompt, so we use run_northstar.txt
fs::write(run_northstar, b"1").unwrap();

let retval = match open::that(format!("steam://run/{}/", TITANFALL2_STEAM_ID)) {
match open::that(format!("steam://run/{}//--northstar/", TITANFALL2_STEAM_ID)) {
Ok(()) => Ok("Started game".to_string()),
Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()),
};

let is_err = retval.is_err();

// Handle the rest in the backround
tauri::async_runtime::spawn(async move {
// Starting the EA app and Titanfall might take a good minute or three
let mut wait_countdown = 60 * 3;
while wait_countdown > 0 && !util::check_northstar_running() && !is_err {
sleep(Duration::from_millis(1000)).await;
wait_countdown -= 1;
}

// Northstar may be running, but it may not have loaded the file yet
sleep(Duration::from_millis(2000)).await;

// intentionally ignore Result
let _ = fs::remove_file(run_northstar);

if Path::new(run_northstar_bak).exists() {
fs::rename(run_northstar_bak, run_northstar).unwrap();
}
});

retval
}
}

0 comments on commit 5911c0e

Please sign in to comment.