From 1970eb80f84ffdae7d5940fde3ff0d400e951c3c Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sun, 5 Feb 2023 22:34:51 +0100 Subject: refactor: Use custom object to expose results Allows for expandability in the future --- src-tauri/bindings/ParsedLogResults.ts | 3 +++ src-tauri/src/repair_and_verify/log_handling.rs | 16 ++++++++++++++-- src-vue/src/views/DeveloperView.vue | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src-tauri/bindings/ParsedLogResults.ts diff --git a/src-tauri/bindings/ParsedLogResults.ts b/src-tauri/bindings/ParsedLogResults.ts new file mode 100644 index 00000000..9d9d5c63 --- /dev/null +++ b/src-tauri/bindings/ParsedLogResults.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ParsedLogResults { installed_mods: Array, } \ No newline at end of file diff --git a/src-tauri/src/repair_and_verify/log_handling.rs b/src-tauri/src/repair_and_verify/log_handling.rs index 3b87f632..6bb6528e 100644 --- a/src-tauri/src/repair_and_verify/log_handling.rs +++ b/src-tauri/src/repair_and_verify/log_handling.rs @@ -1,10 +1,18 @@ use regex::Regex; +use serde::{Deserialize, Serialize}; +use ts_rs::TS; + +#[derive(Serialize, Deserialize, Debug, Clone, TS)] +#[ts(export)] +pub struct ParsedLogResults { + installed_mods: Vec, +} /// Parse logs for installed mods #[tauri::command] pub async fn parse_given_log_text_for_installed_mods( log_text: String, -) -> Result, String> { +) -> Result { // Regex to capture mod loading let regex = Regex::new(r"(?m)Loaded mod (.*) successfully\n").unwrap(); @@ -22,6 +30,10 @@ pub async fn parse_given_log_text_for_installed_mods( }; } + let parsed_log_results = ParsedLogResults { + installed_mods: mods, + }; + // Return the captured mod names - return Ok(mods); + return Ok(parsed_log_results); } diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index b3887ebd..96040189 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -74,6 +74,7 @@ import { invoke } from "@tauri-apps/api"; import { ElNotification } from "element-plus"; import { GameInstall } from "../utils/GameInstall"; import { Store } from 'tauri-plugin-store-api'; +import { ParsedLogResults } from "../../../src-tauri/bindings/ParsedLogResults"; const persistentStore = new Store('flight-core-settings.json'); import { ref } from 'vue' @@ -227,7 +228,7 @@ export default defineComponent({ }, async parseGivenLogTextForMods() { let current_log_content = this.log_content; - await invoke("parse_given_log_text_for_installed_mods", { logText: current_log_content }) + await invoke<[ParsedLogResults]>("parse_given_log_text_for_installed_mods", { logText: current_log_content }) .then((message) => { console.log(message); // TODO present better here // Show user notification if task completed. -- cgit v1.2.3