From a7afc472c1ce2ab6d68b4e2f8a201239f73a5af1 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Tue, 25 Jan 2022 18:29:41 +0200 Subject: [PATCH] Several changes - `cache.json` file was renamed to `.cache.json` - `Patch.fetchTimeout` was increased up to 5 seconds from 3 seconds - fixed *possible* issue with `Locales.default()` method: before, if you've been passing there a language to set as default, it wasn't returning properly - added notification when all the patch repos are not available --- src/ts/Constants.ts | 2 +- src/ts/Patch.ts | 2 +- src/ts/launcher/Locales.ts | 6 ++++- src/ts/launcher/State.ts | 53 +++++++++++++++++++++++++------------- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/ts/Constants.ts b/src/ts/Constants.ts index b412972..8f0a4d8 100644 --- a/src/ts/Constants.ts +++ b/src/ts/Constants.ts @@ -104,7 +104,7 @@ class Paths */ public static get cache(): Promise { - return new Promise(async (resolve) => resolve(`${await this.launcherDir}/cache.json`)); + return new Promise(async (resolve) => resolve(`${await this.launcherDir}/.cache.json`)); } public static readonly prefix = Prefix; diff --git a/src/ts/Patch.ts b/src/ts/Patch.ts index 33e2989..5fc4477 100644 --- a/src/ts/Patch.ts +++ b/src/ts/Patch.ts @@ -126,7 +126,7 @@ class Stream extends AbstractInstaller export default class Patch { - public static fetchTimeout: number|null = 3000; + public static fetchTimeout: number|null = 5000; /** * Get information about latest available patch diff --git a/src/ts/launcher/Locales.ts b/src/ts/launcher/Locales.ts index 197070f..c3303dd 100644 --- a/src/ts/launcher/Locales.ts +++ b/src/ts/launcher/Locales.ts @@ -32,9 +32,13 @@ export default class Locales public static default(lang: AvailableLocales|null = null): Promise { if (lang !== null) + { Configs.set('lang.launcher', lang); - return Configs.get('lang.launcher') as Promise; + return Promise.resolve(lang); + } + + else return Configs.get('lang.launcher') as Promise; } /** diff --git a/src/ts/launcher/State.ts b/src/ts/launcher/State.ts index 979080c..d8bfbb6 100644 --- a/src/ts/launcher/State.ts +++ b/src/ts/launcher/State.ts @@ -368,28 +368,45 @@ export default class State else { - const patch = await Patch.latest; - - // If the latest game version is, for example, 2.3.0 - // and the patch is 2.4.0 preparation, it means that - // 2.4.0 will be released soon, but since it's still not released - // we shouldn't show something about it to user and just let him play the game - if (gameLatest.game.latest.version === patch.version && !patch.applied) + try { - state = patch.state == 'preparation' ? - 'patch-unavailable' : (patch.state == 'testing' ? - 'test-patch-available' : 'patch-available'); + const patch = await Patch.latest; + + // If the latest game version is, for example, 2.3.0 + // and the patch is 2.4.0 preparation, it means that + // 2.4.0 will be released soon, but since it's still not released + // we shouldn't show something about it to user and just let him play the game + if (gameLatest.game.latest.version === patch.version && !patch.applied) + { + state = patch.state == 'preparation' ? + 'patch-unavailable' : (patch.state == 'testing' ? + 'test-patch-available' : 'patch-available'); + } + + // Patch is more important than game pre-downloading + // because otherwise we will not be able to play the game + else if (gameLatest.pre_download_game && !await Game.isUpdatePredownloaded()) + state = 'game-pre-installation-available'; + + else if (gameLatest.pre_download_game && !await Voice.isUpdatePredownloaded(await Voice.selected)) + state = 'game-voice-pre-installation-available'; + + else state = 'game-launch-available'; } - // Patch is more important than game pre-downloading - // because otherwise we will not be able to play the game - else if (gameLatest.pre_download_game && !await Game.isUpdatePredownloaded()) - state = 'game-pre-installation-available'; + // Patch.latest can throw an error if all of patch's servers + // are not available, and we must notify user about that + catch + { + state = 'game-launch-available'; - else if (gameLatest.pre_download_game && !await Voice.isUpdatePredownloaded(await Voice.selected)) - state = 'game-voice-pre-installation-available'; - - else state = 'game-launch-available'; + Notifications.show({ + title: 'An Anime Game Launcher', + body: 'All the patch repositories are not available. You\'ll be able to run the game, but launcher can\'t be sure is it patched properly', + icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, + importance: 'critical' + }); + } } } }