diff options
author | Rémy Raes <contact@remyraes.com> | 2022-09-22 22:35:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-22 22:35:31 +0200 |
commit | 6b7f92b062ab8d4ed7ccd8cc84663b9cab63ec2f (patch) | |
tree | 52f34da65eb5bf79eb4f7771c285591ade5ef6d4 | |
parent | 41cf93b7121fe2bd83a5428ebd20ace5beb60866 (diff) | |
parent | 7be562965057dddd0719646c5bb7fb48574bb3a2 (diff) | |
download | FlightCore-6b7f92b062ab8d4ed7ccd8cc84663b9cab63ec2f.tar.gz FlightCore-6b7f92b062ab8d4ed7ccd8cc84663b9cab63ec2f.zip |
Merge branch 'GeckoEidechse:main' into feat/new-ui
-rw-r--r-- | .vscode/extensions.json | 6 | ||||
-rw-r--r-- | package-lock.json | 26 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | src-tauri/Cargo.lock | 15 | ||||
-rw-r--r-- | src-tauri/Cargo.toml | 4 | ||||
-rw-r--r-- | src-tauri/src/lib.rs | 47 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 44 | ||||
-rw-r--r-- | src-tauri/tauri.conf.json | 2 | ||||
-rw-r--r-- | src-ui/src/main.ts | 71 |
9 files changed, 167 insertions, 51 deletions
diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..dc972647 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "tauri-apps.tauri-vscode", + "rust-lang.rust-analyzer" + ] +}
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8b31a082..80466586 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,8 @@ "": { "name": "flightcore", "dependencies": { - "@tauri-apps/api": "^1.1.0" + "@tauri-apps/api": "^1.1.0", + "tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#dev" }, "devDependencies": { "@rollup/plugin-node-resolve": "^13.3.0", @@ -447,11 +448,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/tauri-plugin-store-api": { + "version": "0.1.0", + "resolved": "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#d8efb964bb1894bdf01407693ee896d0f9c557b3", + "license": "MIT", + "dependencies": { + "@tauri-apps/api": "1.1.0", + "tslib": "2.4.0" + } + }, "node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", - "dev": true + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" }, "node_modules/typescript": { "version": "4.8.3", @@ -717,11 +726,18 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "tauri-plugin-store-api": { + "version": "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#d8efb964bb1894bdf01407693ee896d0f9c557b3", + "from": "tauri-plugin-store-api@https://github.com/tauri-apps/tauri-plugin-store#dev", + "requires": { + "@tauri-apps/api": "1.1.0", + "tslib": "2.4.0" + } + }, "tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", - "dev": true + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" }, "typescript": { "version": "4.8.3", diff --git a/package.json b/package.json index 5430f4c6..c45d7222 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "ui-dev": "./node_modules/.bin/rollup --config --watch & npm run localhost" }, "dependencies": { - "@tauri-apps/api": "^1.1.0" + "@tauri-apps/api": "^1.1.0", + "tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#dev" }, "devDependencies": { "@rollup/plugin-node-resolve": "^13.3.0", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 624586d6..76a513d6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -76,7 +76,7 @@ checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "app" -version = "0.1.2" +version = "0.1.5" dependencies = [ "anyhow", "libthermite", @@ -90,6 +90,7 @@ dependencies = [ "sysinfo", "tauri", "tauri-build", + "tauri-plugin-store", "tokio", "zip", ] @@ -3467,6 +3468,18 @@ dependencies = [ ] [[package]] +name = "tauri-plugin-store" +version = "0.0.0" +source = "git+https://github.com/tauri-apps/tauri-plugin-store?branch=dev#d8efb964bb1894bdf01407693ee896d0f9c557b3" +dependencies = [ + "log", + "serde", + "serde_json", + "tauri", + "thiserror", +] + +[[package]] name = "tauri-runtime" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ff8a8c44..5f2cce4d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.1.2" +version = "0.1.5" description = "A Tauri App" authors = ["you"] license = "" @@ -36,6 +36,8 @@ regex = "1.6.0" sysinfo = "0.26.2" # HTTP requests reqwest = { version = "0.11", features = ["blocking"] } +# Persistent store for settings +tauri-plugin-store = { git = "https://github.com/tauri-apps/tauri-plugin-store", branch = "dev" } [features] # by default Tauri runs in production mode 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) +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ff4a4761..a1a83c2e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "flightcore", - "version": "0.1.2" + "version": "0.1.5" }, "tauri": { "allowlist": { diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 3841d3a0..3b47e6f4 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -2,6 +2,9 @@ import { invoke } from "@tauri-apps/api"; import { listen, Event as TauriEvent } from "@tauri-apps/api/event"; import { open } from '@tauri-apps/api/dialog'; import { appDir } from '@tauri-apps/api/path'; +import { Store } from 'tauri-plugin-store-api'; + +const store = new Store('flight-core-settings.json'); const $ = document.querySelector.bind(document); const button_install_string = "Install Northstar"; @@ -87,9 +90,6 @@ async function manually_find_titanfall2_install(omniButtonEl: HTMLElement) { document.addEventListener("DOMContentLoaded", async function () { // get the elements - // const helloEl = $("div.hello")! as HTMLElement; - // let counterButtonEl = $("counter-button") as HTMLElement; - // let counterResultEl = $("counter-result") as HTMLElement; let pingEl = $("backend-ping")! as HTMLElement; let panicButtonEl = $("panic-button") as HTMLElement; let installLocationHolderEl = document.getElementById("install-location-holder") as HTMLInputElement; @@ -100,7 +100,7 @@ document.addEventListener("DOMContentLoaded", async function () { let northstarVersionHolderEl = $("northstar-version-holder") as HTMLElement; let useReleaseCandidateCheckboxEl = document.getElementById("use-release-candidate-checkbox") as HTMLInputElement; - useReleaseCandidateCheckboxEl.addEventListener('change', function () { + useReleaseCandidateCheckboxEl.addEventListener('change', async function () { // Switch between main release and release candidates if (this.checked) { globalState.northstar_package_name = "NorthstarReleaseCandidate" @@ -109,6 +109,9 @@ document.addEventListener("DOMContentLoaded", async function () { } // Update the button get_northstar_version_number_and_set_button_accordingly(omniButtonEl); + + // Save change in persistent store + await store.set('northstar-package-name', { value: globalState.northstar_package_name }); }); // listen backend-ping event (from Tauri Rust App) @@ -129,7 +132,23 @@ document.addEventListener("DOMContentLoaded", async function () { originRunningHolderEl.textContent = "ORIGIN NOT RUNNING"; } console.log(evt.payload); - }) + }); + + // listen northstar-running-ping event (from Tauri Rust App) + listen("northstar-running-ping", function (evt: TauriEvent<any>) { + 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 () { @@ -208,21 +227,6 @@ document.addEventListener("DOMContentLoaded", async function () { } }); - // // counter button click - // counterButtonEl.addEventListener("pointerup", async function () { - // const result = await invoke("add_count", { num: 1 }) as string; - // counterResultEl.textContent = result; - // }); - - // // hello click - // helloEl.addEventListener("pointerup", async function () { - // const result = await invoke("hello_world") as string; - // helloEl.textContent = result; - // setTimeout(function () { - // helloEl.textContent = "Click again"; - // }, 1000); - // }) - // panic button click panicButtonEl.addEventListener("pointerup", async function () { await invoke("force_panic"); @@ -239,6 +243,18 @@ document.addEventListener("DOMContentLoaded", async function () { let host_os_string = await invoke("get_host_os_caller") as string; versionNumberHolderEl.textContent = `${version_number_string} (${host_os_string})${outdated_string}`; + // Get preferred Northstar version from persistent store + const persistent_northstar_package_name_obj = ((await store.get('northstar-package-name')) as any); + if (persistent_northstar_package_name_obj) { + console.log(persistent_northstar_package_name_obj) + globalState.northstar_package_name = persistent_northstar_package_name_obj.value as string; + // Update checkbox if it's a ReleaseCandidate + // In the future this might be a dropdown menu instead + if (globalState.northstar_package_name === "NorthstarReleaseCandidate") { + useReleaseCandidateCheckboxEl.checked = true; + } + } + // Get install location await invoke("find_game_install_location_caller", { gamePath: globalState.gamepath }) .then((game_install) => { @@ -267,4 +283,19 @@ 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); + }); + // ------------------------------------------------------------------ + }) |