From 5333f4e19d80be6ff48772b6d35cbe89cc8b04b9 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Tue, 20 Sep 2022 15:06:29 +0200 Subject: Move dependency import to top of file --- src-tauri/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/lib.rs') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 6428ce2e..f2fef1da 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, Context, Result}; use powershell_script::PsScriptBuilder; use regex::Regex; use serde::{Deserialize, Serialize}; +use sysinfo::SystemExt; use zip::ZipArchive; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -323,9 +324,8 @@ pub fn launch_northstar(game_install: GameInstall) -> Result { )) } -use sysinfo::{System, SystemExt}; pub fn check_origin_running() -> bool { - let s = System::new_all(); + let s = sysinfo::System::new_all(); for _process in s.processes_by_name("Origin.exe") { // check here if this is your process // dbg!(process); -- cgit v1.2.3 From 3abf70c34f5a354afd89b10017ffda05aad4e54f Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Tue, 20 Sep 2022 15:35:49 +0200 Subject: Periodically check if Northstar is running --- src-tauri/src/lib.rs | 11 +++++++++++ src-tauri/src/main.rs | 15 ++++++++++++--- src-ui/src/main.ts | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src-tauri/src/lib.rs') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f2fef1da..9856394d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -334,6 +334,17 @@ pub fn check_origin_running() -> bool { false } +/// Checks if Northstar process is running +pub fn check_northstar_running() -> bool { + let s = sysinfo::System::new_all(); + for _process in s.processes_by_name("NorthstarLauncher.exe") { + // check here if this is your process + // dbg!(process); + return true; + } + false +} + /// Helps with converting release candidate numbers which are different on Thunderstore /// due to restrictions imposed by the platform pub fn convert_release_candidate_number(version_number: String) -> String { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 20ad4716..c6c51e2b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,9 +10,9 @@ use std::{ }; use app::{ - check_is_flightcore_outdated, check_is_valid_game_path, check_origin_running, - convert_release_candidate_number, find_game_install_location, get_host_os, - get_northstar_version_number, install_northstar, launch_northstar, GameInstall, + check_is_flightcore_outdated, check_is_valid_game_path, check_northstar_running, + check_origin_running, convert_release_candidate_number, find_game_install_location, + get_host_os, get_northstar_version_number, install_northstar, launch_northstar, GameInstall, }; use tauri::{Manager, State}; use tokio::time::sleep; @@ -50,6 +50,15 @@ fn main() { .unwrap(); } }); + let app_handle = app.app_handle(); + tauri::async_runtime::spawn(async move { + loop { + sleep(Duration::from_millis(2000)).await; + app_handle + .emit_all("northstar-running-ping", check_northstar_running()) + .unwrap(); + } + }); Ok(()) }) diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index df88af15..f7aa6ec6 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -131,6 +131,22 @@ document.addEventListener("DOMContentLoaded", async function () { console.log(evt.payload); }); + // listen northstar-running-ping event (from Tauri Rust App) + listen("northstar-running-ping", function (evt: TauriEvent) { + let northstar_is_running = evt.payload as boolean; + if (northstar_is_running) { + omniButtonEl.textContent = button_launched_string; + } + else { + // Only set button to launch Northstar if was running before + // Otherwise we'd have to check on each access if Titanfall2 path set, Northstar is installed, etc. + if (omniButtonEl.textContent == button_launched_string) { + omniButtonEl.textContent = button_play_string; + } + } + console.log(evt.payload); + }); + // omni button click omniButtonEl.addEventListener("click", async function () { -- cgit v1.2.3 From 0dd0cf6f370abb602399b94711e6eff1002ddfcf Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Thu, 22 Sep 2022 16:31:42 +0200 Subject: Import OS specifc libraries only on that OS --- src-tauri/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src-tauri/src/lib.rs') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9856394d..2ea9571b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,8 +1,12 @@ use std::env; use anyhow::{anyhow, Context, Result}; + +#[cfg(target_os = "windows")] use powershell_script::PsScriptBuilder; +#[cfg(target_os = "windows")] use regex::Regex; + use serde::{Deserialize, Serialize}; use sysinfo::SystemExt; use zip::ZipArchive; -- cgit v1.2.3 From bc0c8ead3f120402ada48780d1be42259384e0f4 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Thu, 22 Sep 2022 17:08:25 +0200 Subject: Add initial functionality to get NS log files --- src-tauri/src/lib.rs | 28 ++++++++++++++++++++++++++++ src-tauri/src/main.rs | 12 ++++++++++-- src-ui/src/main.ts | 16 ++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/lib.rs') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2ea9571b..f19a178c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -393,3 +393,31 @@ pub fn check_is_flightcore_outdated() -> Result { // TODO: This shouldn't be a string compare but promper semver compare Ok(version != newest_release_version) } + +pub fn get_log_list(game_install: GameInstall) -> Result, String> { + let ns_log_folder = format!("{}/R2Northstar/logs", game_install.game_path); + + // Check if logs folder exists + if !std::path::Path::new(&ns_log_folder).exists() { + return Err("No logs folder found".to_string()); + } + + // List files in logs folder + let paths = std::fs::read_dir(ns_log_folder).unwrap(); + + // Stores paths of log files + let mut log_files: Vec = Vec::new(); + + for path in paths { + let path = path.unwrap().path(); + if path.display().to_string().contains("nslog") { + log_files.push(path); + } + } + + if log_files.len() > 0 { + Ok(log_files) + } else { + Err("No logs found".to_string()) + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 492c5935..945d6528 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -12,7 +12,8 @@ use std::{ use app::{ check_is_flightcore_outdated, check_is_valid_game_path, check_northstar_running, check_origin_running, convert_release_candidate_number, find_game_install_location, - get_host_os, get_northstar_version_number, install_northstar, launch_northstar, GameInstall, + get_host_os, get_log_list, get_northstar_version_number, install_northstar, launch_northstar, + GameInstall, }; use tauri::{Manager, State}; use tokio::time::sleep; @@ -78,7 +79,8 @@ fn main() { install_northstar_caller, update_northstar_caller, launch_northstar_caller, - check_is_flightcore_outdated_caller + check_is_flightcore_outdated_caller, + get_log_list_caller ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -247,3 +249,9 @@ async fn update_northstar_caller( fn launch_northstar_caller(game_install: GameInstall) -> Result { launch_northstar(game_install) } + +#[tauri::command] +/// Get list of Northstar logs +fn get_log_list_caller(game_install: GameInstall) -> Result, String> { + get_log_list(game_install) +} diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index dd28fedc..0505f0c2 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -301,4 +301,20 @@ document.addEventListener("DOMContentLoaded", async function () { alert(error); omniButtonEl.textContent = button_manual_find_string; }); + + + // --- This should be moved and is only placed here temporarily ----- + let game_install = { + game_path: globalState.gamepath, + install_type: installTypeHolderEl.textContent + } as GameInstall; + await invoke("get_log_list_caller", { gameInstall: game_install }) + .then((message) => { + console.log(message); + }) + .catch((error) => { + console.error(error); + }); + // ------------------------------------------------------------------ + }) -- cgit v1.2.3