From 238e340ffb4d1af175e29567a772a0790174fdff Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 27 Sep 2022 23:33:17 +0200 Subject: feat: we can now install Northstar if it wasn't detected --- src-vue/src/plugins/store.ts | 27 ++++++++++++++++++++++++--- src-vue/src/utils/NorthstarState.ts | 7 +++++++ src-vue/src/views/PlayView.vue | 21 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src-vue/src/utils/NorthstarState.ts (limited to 'src-vue') diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 58756a92..62d6f3ff 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -5,6 +5,7 @@ import {invoke} from "@tauri-apps/api"; import {GameInstall} from "../utils/GameInstall"; import {ReleaseCanal} from "../utils/ReleaseCanal"; import { ElNotification } from 'element-plus'; +import { NorthstarState } from '../utils/NorthstarState'; export const store = createStore({ state () { @@ -14,6 +15,7 @@ export const store = createStore({ game_path: "this/is/the/game/path", installed_northstar_version: "", + northstar_state: NorthstarState.INSTALL, northstar_is_running: false, origin_is_running: false @@ -36,9 +38,25 @@ export const store = createStore({ updateCurrentTab(state: any, newTab: Tabs) { state.current_tab = newTab; }, - launchGame(state: any) { + async launchGame(state: any) { // TODO update installation if release track was switched - // TODO install northstar if it wasn't detected + + // Install northstar if it wasn't detected. + if (state.northstar_state === NorthstarState.INSTALL) { + let install_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_path, northstarPackageName: ReleaseCanal.RELEASE }); + state.northstar_state = NorthstarState.INSTALLING; + + await install_northstar_result.then((message) => { + console.log(message); + }) + .catch((error) => { + console.error(error); + alert(error); + }); + + _get_northstar_version_number(state); + } + // Show an error message if Origin is not running. if (!state.origin_is_running) { ElNotification({ @@ -101,10 +119,13 @@ 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) { 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: ReleaseCanal.RELEASE }) .then((message) => { - console.log(message); + if (message) { + state.northstar_state = NorthstarState.MUST_UPDATE; + } }) .catch((error) => { console.error(error); diff --git a/src-vue/src/utils/NorthstarState.ts b/src-vue/src/utils/NorthstarState.ts new file mode 100644 index 00000000..d6e31923 --- /dev/null +++ b/src-vue/src/utils/NorthstarState.ts @@ -0,0 +1,7 @@ +export enum NorthstarState { + INSTALL, + INSTALLING, + MUST_UPDATE, + UPDATING, + READY_TO_PLAY +} \ No newline at end of file diff --git a/src-vue/src/views/PlayView.vue b/src-vue/src/views/PlayView.vue index 02d59b15..03f54936 100644 --- a/src-vue/src/views/PlayView.vue +++ b/src-vue/src/views/PlayView.vue @@ -1,5 +1,6 @@