From 252c2ca40d805e8190b70e5599e44ee632a99778 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sun, 5 Feb 2023 23:02:41 +0100 Subject: refactor: Use wrapper function that calls into dedicated parser functions and then assemble object inside the wrapper function --- src-tauri/src/main.rs | 4 ++-- src-tauri/src/repair_and_verify/log_handling.rs | 20 ++++++++++++-------- src-vue/src/views/DeveloperView.vue | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 06adf784..015ac925 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -37,7 +37,7 @@ use tauri::Manager; use tauri_plugin_store::PluginBuilder; use tokio::time::sleep; -use crate::repair_and_verify::log_handling::parse_given_log_text_for_installed_mods; +use crate::repair_and_verify::log_handling::parse_given_log_text; #[derive(Default)] struct Counter(Arc>); @@ -112,7 +112,7 @@ fn main() { delete_northstar_mod, get_server_player_count, delete_thunderstore_mod, - parse_given_log_text_for_installed_mods, + parse_given_log_text, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/repair_and_verify/log_handling.rs b/src-tauri/src/repair_and_verify/log_handling.rs index 6bb6528e..2b394a23 100644 --- a/src-tauri/src/repair_and_verify/log_handling.rs +++ b/src-tauri/src/repair_and_verify/log_handling.rs @@ -9,10 +9,7 @@ pub struct ParsedLogResults { } /// Parse logs for installed mods -#[tauri::command] -pub async fn parse_given_log_text_for_installed_mods( - log_text: String, -) -> Result { +fn parse_given_log_text_for_installed_mods(log_text: String) -> Result, String> { // Regex to capture mod loading let regex = Regex::new(r"(?m)Loaded mod (.*) successfully\n").unwrap(); @@ -30,10 +27,17 @@ 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); +} + +/// Parse logs for installed mods +#[tauri::command] +pub async fn parse_given_log_text(log_text: String) -> Result { + let installed_mods = parse_given_log_text_for_installed_mods(log_text)?; + + let parsed_log_results = ParsedLogResults { installed_mods }; + + // Return the parsed results return Ok(parsed_log_results); } diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index 87ee7772..d8423450 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -225,7 +225,7 @@ export default defineComponent({ }, async parseGivenLogTextForMods() { let current_log_content = this.log_content; - await invoke<[ParsedLogResults]>("parse_given_log_text_for_installed_mods", { logText: current_log_content }) + await invoke<[ParsedLogResults]>("parse_given_log_text", { logText: current_log_content }) .then((message) => { console.log(message); // TODO present better here // Show user notification if task completed. -- cgit v1.2.3