aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 23:30:50 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 23:30:50 +0200
commitb7273effece9e1ad46f18e843cd8a0e5f876cc64 (patch)
tree35d06cf4910d039ed1de984715d449b6de0490a9
parent54e5b393128f6df4c013ff0866349cce4291d7b5 (diff)
downloadFlightCore-b7273effece9e1ad46f18e843cd8a0e5f876cc64.tar.gz
FlightCore-b7273effece9e1ad46f18e843cd8a0e5f876cc64.zip
Move launching Northstar to lib.rs source file
-rw-r--r--src-tauri/src/lib.rs37
-rw-r--r--src-tauri/src/main.rs42
-rw-r--r--src-ui/src/main.ts2
3 files changed, 42 insertions, 39 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index d1073387..9a3cd471 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -251,3 +251,40 @@ pub async fn install_northstar(game_path: &str) -> Result<String> {
pub fn get_host_os() -> String {
env::consts::OS.to_string()
}
+
+pub fn launch_northstar(game_install: GameInstall) -> Result<String, String> {
+ dbg!(game_install.clone());
+
+ // Some safety checks before, should have more in the future
+ if get_northstar_version_number(game_install.game_path.clone()).is_err() {
+ return Err(anyhow!("Not all checks were met").to_string());
+ }
+
+ let host_os = get_host_os();
+
+ // Switch to Titanfall2 directory for launching
+ // NorthstarLauncher.exe expects to be run from that folder
+ if std::env::set_current_dir(game_install.game_path.clone()).is_err() {
+ // We failed to get to Titanfall2 directory
+ return Err(anyhow!("Couldn't access Titanfall2 directory").to_string());
+ }
+
+ // Only Windows with Steam or Origin are supported at the moment
+ if host_os == "windows"
+ && (matches!(game_install.install_type, InstallType::STEAM)
+ || matches!(game_install.install_type, InstallType::ORIGIN))
+ {
+ let _output =
+ std::process::Command::new(format!("{}/NorthstarLauncher.exe", game_install.game_path))
+ // .args(&["a", "b"])
+ .spawn()
+ .expect("failed to execute process");
+ return Ok("Launched game".to_string());
+ }
+
+ Err(format!(
+ "Not yet implemented for {:?} on {}",
+ game_install.install_type,
+ get_host_os()
+ ))
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 0b436262..9b90c13d 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -9,10 +9,9 @@ use std::{
time::Duration,
};
-use anyhow::anyhow;
use app::{
check_is_valid_game_path, find_game_install_location, get_northstar_version_number,
- install_northstar, GameInstall, InstallType, get_host_os,
+ install_northstar, GameInstall, launch_northstar, get_host_os,
};
use tauri::{Manager, State};
use tokio::time::sleep;
@@ -57,7 +56,7 @@ fn main() {
get_host_os_caller,
install_northstar_caller,
update_northstar_caller,
- launch_northstar
+ launch_northstar_caller
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -192,39 +191,6 @@ async fn update_northstar_caller(game_path: String) -> Result<bool, String> {
#[tauri::command]
/// Launches Northstar
-fn launch_northstar(game_install: GameInstall) -> Result<String, String> {
- dbg!(game_install.clone());
-
- // Some safety checks before, should have more in the future
- if get_northstar_version_number(game_install.game_path.clone()).is_err() {
- return Err(anyhow!("Not all checks were met").to_string());
- }
-
- let host_os = get_host_os();
-
- // Switch to Titanfall2 directory for launching
- // NorthstarLauncher.exe expects to be run from that folder
- if std::env::set_current_dir(game_install.game_path.clone()).is_err() {
- // We failed to get to Titanfall2 directory
- return Err(anyhow!("Couldn't access Titanfall2 directory").to_string());
- }
-
- // Only Windows with Steam or Origin are supported at the moment
- if host_os == "windows"
- && (matches!(game_install.install_type, InstallType::STEAM)
- || matches!(game_install.install_type, InstallType::ORIGIN))
- {
- let _output =
- std::process::Command::new(format!("{}/NorthstarLauncher.exe", game_install.game_path))
- // .args(&["a", "b"])
- .spawn()
- .expect("failed to execute process");
- return Ok("Launched game".to_string());
- }
-
- Err(format!(
- "Not yet implemented for {:?} on {}",
- game_install.install_type,
- get_host_os()
- ))
+fn launch_northstar_caller(game_install: GameInstall) -> Result<String, String> {
+ launch_northstar(game_install)
}
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index fb61ac4a..0a2c5401 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -152,7 +152,7 @@ document.addEventListener("DOMContentLoaded", async function () {
game_path: globalState.gamepath,
install_type: installTypeHolderEl.textContent
} as GameInstall;
- await invoke("launch_northstar", { gameInstall: game_install })
+ await invoke("launch_northstar_caller", { gameInstall: game_install })
.then((message) => {
console.log(message);
omniButtonEl.textContent = `${button_launched_string} (v${globalState.installed_northstar_version})`;