aboutsummaryrefslogtreecommitdiff
path: root/src-vue/src/plugins/store.ts
diff options
context:
space:
mode:
authorRemy Raes <raes.remy@gmail.com>2022-10-03 18:15:36 +0200
committerRemy Raes <raes.remy@gmail.com>2022-10-03 18:15:36 +0200
commit98d0e35e5a6e9966406e968e2d247e5e9b6f7768 (patch)
treed3a3cbbd219060f6652ad035b30134982e305f7d /src-vue/src/plugins/store.ts
parent03f56784b021718aa3410314cb6364ead831aa08 (diff)
downloadFlightCore-98d0e35e5a6e9966406e968e2d247e5e9b6f7768.tar.gz
FlightCore-98d0e35e5a6e9966406e968e2d247e5e9b6f7768.zip
refactor: implement launchGame method with switch/case
Diffstat (limited to 'src-vue/src/plugins/store.ts')
-rw-r--r--src-vue/src/plugins/store.ts116
1 files changed, 57 insertions, 59 deletions
diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts
index 5087221b..62b1f887 100644
--- a/src-vue/src/plugins/store.ts
+++ b/src-vue/src/plugins/store.ts
@@ -58,71 +58,69 @@ export const store = createStore({
},
async launchGame(state: any) {
// TODO update installation if release track was switched
+ switch (state.northstar_state) {
+ // Install northstar if it wasn't detected.
+ case NorthstarState.INSTALL:
+ let install_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_path, northstarPackageName: ReleaseCanal.RELEASE });
+ state.northstar_state = NorthstarState.INSTALLING;
- // 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);
- return;
- }
+ await install_northstar_result.then((message) => {
+ console.log(message);
+ })
+ .catch((error) => {
+ console.error(error);
+ alert(error);
+ });
- // Update northstar if it is outdated.
- if (state.northstar_state === NorthstarState.MUST_UPDATE) {
- // Updating is the same as installing, simply overwrites the existing files
- let install_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_path, northstarPackageName: ReleaseCanal.RELEASE });
- state.northstar_state = NorthstarState.UPDATING;
-
- await install_northstar_result.then((message) => {
- console.log(message);
- })
- .catch((error) => {
- console.error(error);
- alert(error);
- });
-
- _get_northstar_version_number(state);
- return;
- }
+ _get_northstar_version_number(state);
+ break;
- // Game is ready to play
- if (state.northstar_state === NorthstarState.READY_TO_PLAY) {
- // Show an error message if Origin is not running.
- if (!state.origin_is_running) {
- ElNotification({
- title: 'Origin is not running',
- message: "Northstar cannot launch while you're not authenticated with Origin.",
- type: 'warning',
- position: 'bottom-right'
- });
-
- // If Origin isn't running, end here
- return;
- }
+ // Update northstar if it is outdated.
+ case NorthstarState.MUST_UPDATE:
+ // Updating is the same as installing, simply overwrites the existing files
+ let reinstall_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_path, northstarPackageName: ReleaseCanal.RELEASE });
+ state.northstar_state = NorthstarState.UPDATING;
- let game_install = {
- game_path: state.game_path,
- install_type: state.install_type
- } as GameInstall;
- await invoke("launch_northstar_caller", { gameInstall: game_install })
- .then((message) => {
+ await reinstall_northstar_result.then((message) => {
console.log(message);
- // NorthstarState.RUNNING
})
- .catch((error) => {
- console.error(error);
- alert(error);
- });
- return;
+ .catch((error) => {
+ console.error(error);
+ alert(error);
+ });
+
+ _get_northstar_version_number(state);
+ break;
+
+ // Game is ready to play.
+ case NorthstarState.READY_TO_PLAY:
+ // Show an error message if Origin is not running.
+ if (!state.origin_is_running) {
+ ElNotification({
+ title: 'Origin is not running',
+ message: "Northstar cannot launch while you're not authenticated with Origin.",
+ type: 'warning',
+ position: 'bottom-right'
+ });
+
+ // If Origin isn't running, end here
+ return;
+ }
+
+ let game_install = {
+ game_path: state.game_path,
+ install_type: state.install_type
+ } as GameInstall;
+ await invoke("launch_northstar_caller", { gameInstall: game_install })
+ .then((message) => {
+ console.log(message);
+ // NorthstarState.RUNNING
+ })
+ .catch((error) => {
+ console.error(error);
+ alert(error);
+ });
+ break;
}
}
}