From 128c9af70f92703589894971769230075bc09e96 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:15:30 +0100 Subject: refactor: Return Result<> for getting NS version (#46) as opposed to using an empty string to indicate an error. --- src-tauri/src/main.rs | 9 +++------ src-vue/src/plugins/store.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0210cabb..ad5842f4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -146,13 +146,10 @@ async fn get_flightcore_version_number() -> String { } #[tauri::command] -async fn get_northstar_version_number_caller(game_path: String) -> String { +async fn get_northstar_version_number_caller(game_path: String) -> Result { match get_northstar_version_number(game_path) { - Ok(version_number) => version_number, - Err(err) => { - println!("{}", err); - "".to_string() - } + Ok(version_number) => Ok(version_number), + Err(err) => Err(err.to_string()), } } diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 31b1efec..8f1f9fe5 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -269,12 +269,13 @@ function _initializeListeners(state: any) { * state, for it to be displayed in UI. */ async function _get_northstar_version_number(state: any) { - let northstar_version_number: string = await invoke("get_northstar_version_number_caller", { gamePath: state.game_path }); - if (northstar_version_number && northstar_version_number.length > 0) { + await invoke("get_northstar_version_number_caller", { gamePath: state.game_path }) + .then((message) => { + let northstar_version_number: string = message as string; state.installed_northstar_version = northstar_version_number; state.northstar_state = NorthstarState.READY_TO_PLAY; - await invoke("check_is_northstar_outdated", { gamePath: state.game_path, northstarPackageName: state.northstar_release_canal }) + invoke("check_is_northstar_outdated", { gamePath: state.game_path, northstarPackageName: state.northstar_release_canal }) .then((message) => { if (message) { state.northstar_state = NorthstarState.MUST_UPDATE; @@ -284,8 +285,8 @@ async function _get_northstar_version_number(state: any) { console.error(error); alert(error); }); - } - else { + }) + .catch((error) => { state.northstar_state = NorthstarState.INSTALL; - } + }) } -- cgit v1.2.3