aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/lib.rs47
-rw-r--r--src-tauri/src/main.rs44
2 files changed, 69 insertions, 22 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 6428ce2e..f19a178c 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1,9 +1,14 @@
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;
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -323,9 +328,8 @@ pub fn launch_northstar(game_install: GameInstall) -> Result<String, String> {
))
}
-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);
@@ -334,6 +338,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 {
@@ -378,3 +393,31 @@ pub fn check_is_flightcore_outdated() -> Result<bool, String> {
// 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<Vec<std::path::PathBuf>, 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<std::path::PathBuf> = 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 20ad4716..536acbe5 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -10,12 +10,14 @@ 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_log_list, get_northstar_version_number, install_northstar, launch_northstar,
+ GameInstall,
};
-use tauri::{Manager, State};
+use tauri::Manager;
use tokio::time::sleep;
+use tauri_plugin_store::PluginBuilder;
#[derive(Default)]
struct Counter(Arc<Mutex<i32>>);
@@ -32,6 +34,7 @@ fn main() {
));
tauri::Builder::default()
+ .plugin(PluginBuilder::default().build())
.setup(|app| {
let app_handle = app.app_handle();
tauri::async_runtime::spawn(async move {
@@ -50,13 +53,20 @@ 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(())
})
.manage(Counter(Default::default()))
.invoke_handler(tauri::generate_handler![
- hello_world,
- add_count,
force_panic,
find_game_install_location_caller,
get_version_number,
@@ -67,7 +77,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");
@@ -86,19 +97,6 @@ fn find_game_install_location_caller() -> Result<GameInstall, String> {
}
#[tauri::command]
-fn hello_world() -> String {
- "Hello World!!!".to_string()
-}
-
-#[tauri::command]
-fn add_count(num: i32, counter: State<'_, Counter>) -> String {
- let mut val = counter.0.lock().unwrap();
- *val += num;
-
- format!("{val}")
-}
-
-#[tauri::command]
/// This function's only use is to force a `panic!()`
fn force_panic() {
panic!("Force panicked!");
@@ -236,3 +234,9 @@ async fn update_northstar_caller(
fn launch_northstar_caller(game_install: GameInstall) -> Result<String, String> {
launch_northstar(game_install)
}
+
+#[tauri::command]
+/// Get list of Northstar logs
+fn get_log_list_caller(game_install: GameInstall) -> Result<Vec<std::path::PathBuf>, String> {
+ get_log_list(game_install)
+}