From 62a5f5c821961c6f7fcc5354c207c6e09895bcb4 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 23 Nov 2022 09:36:27 +0100 Subject: feat: Store game path in persistent store (#61) * feat: Store gameinstall in persistent store This includes both path and type (Steam/Origin/EA/UNKNOWN) * feat: Add method to clear persistent store * fix: Only check for NS version if installed Otherwise we incorrectly set the button to `Install`. * fix: Remove leftover `console.log()` --- src-vue/src/plugins/store.ts | 70 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 'src-vue/src/plugins') diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 8ebcaf80..e010ca12 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -105,6 +105,14 @@ export const store = createStore({ } state.install_type = InstallType.UNKNOWN; + let game_install = { + game_path: selected, + install_type: InstallType.UNKNOWN + } as GameInstall; + + // Save change in persistent store + await persistentStore.set('game-install', { value: game_install }); + // Check for Northstar install store.commit('checkNorthstarUpdates'); } @@ -226,24 +234,54 @@ async function _initializeApp(state: any) { // Get FlightCore version number state.flightcore_version = await invoke("get_flightcore_version_number"); - const result = await invoke("find_game_install_location_caller") - .catch((err) => { - // Gamepath not found or other error - console.error(err); - notification_handle = ElNotification({ - title: 'Titanfall2 not found!', - message: "Please manually select install location", - type: 'error', - position: 'bottom-right', - duration: 0 // Duration `0` means the notification will not auto-vanish + var result = undefined; + var persistent_game_install = (await persistentStore.get('game-install')) as any; + + if ( // Safety checks for value from store + persistent_game_install + && persistent_game_install.value !== undefined + && persistent_game_install.value.game_path !== undefined + && persistent_game_install.value.install_type !== undefined + ) { // For some reason, the plugin-store doesn't throw an eror but simply returns `null` when key not found + let game_install = persistent_game_install.value as GameInstall; + // check if valid path + let is_valid_titanfall2_install = await invoke("verify_install_location", { gamePath: game_install.game_path }) as boolean; + if (is_valid_titanfall2_install) { + // Use value from peristent store + result = game_install; + } + + } + + if (result === undefined) { // No (valid) value found in persistent store + result = await invoke("find_game_install_location_caller") + .catch((err) => { + // Gamepath not found or other error + console.error(err); + notification_handle = ElNotification({ + title: 'Titanfall2 not found!', + message: "Please manually select install location", + type: 'error', + position: 'bottom-right', + duration: 0 // Duration `0` means the notification will not auto-vanish + }); }); - }); - const typedResult: GameInstall = result as GameInstall; - state.game_path = typedResult.game_path; - state.install_type = typedResult.install_type; + } + + if (result !== undefined) { // Found some form of value for gameinstall + + const typedResult: GameInstall = result as GameInstall; - // Check installed Northstar version if found - await _get_northstar_version_number(state); + // Save change in persistent store + await persistentStore.set('game-install', { value: typedResult }); + + // Update UI store + state.game_path = typedResult.game_path; + state.install_type = typedResult.install_type; + + // Check installed Northstar version if found + await _get_northstar_version_number(state); + } } async function _checkForFlightCoreUpdates(state: FlightCoreStore) { -- cgit v1.2.3