From d1ebf567b7b48401f507e362e6499b50ce09048a Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sun, 20 Feb 2022 14:46:58 +0200 Subject: [PATCH] Added generic types for `Locales.translate()` --- src/tos-violation.svelte | 2 +- src/ts/launcher/Locales.ts | 4 ++-- src/ts/launcher/State.ts | 6 +++--- src/ts/launcher/states/ApplyChanges.ts | 4 ++-- src/ts/launcher/states/ApplyPatch.ts | 6 +++--- src/ts/launcher/states/Install.ts | 8 ++++---- src/ts/launcher/states/Launch.ts | 10 +++++++--- src/ts/launcher/states/RemoveOutdated.ts | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/tos-violation.svelte b/src/tos-violation.svelte index 0fa8f6c..232740a 100644 --- a/src/tos-violation.svelte +++ b/src/tos-violation.svelte @@ -26,7 +26,7 @@ Windows.current.show(); Windows.current.center(); - const title = Locales.translate('tos_violation.title') as string|null; + const title = Locales.translate('tos_violation.title'); if (title) Windows.current.setTitle(title); diff --git a/src/ts/launcher/Locales.ts b/src/ts/launcher/Locales.ts index 1de0c30..d715ca7 100644 --- a/src/ts/launcher/Locales.ts +++ b/src/ts/launcher/Locales.ts @@ -156,7 +156,7 @@ export default class Locales /** * Get translation from the currently selected locale */ - public static translate(message: string): string|object|null + public static translate(message: string): T { const currentDictionary = svelteget(dictionary) as object; @@ -170,7 +170,7 @@ export default class Locales break; } - return translation; + return translation as T; } /** diff --git a/src/ts/launcher/State.ts b/src/ts/launcher/State.ts index 32085f9..ed0f523 100644 --- a/src/ts/launcher/State.ts +++ b/src/ts/launcher/State.ts @@ -143,7 +143,7 @@ export default class State else if (await fs.exists(path.join(await constants.paths.launcherDir, '.analytics'))) { Windows.open('analytics', { - title: Locales.translate('analytics.title') as string, + title: Locales.translate('analytics.title'), width: 700, height: 460, exitProcessOnClose: false @@ -188,7 +188,7 @@ export default class State for (const tag of tags.reverse()) if (semver.gt(tag.tag, Launcher.version)) { - const locales = Locales.translate('notifications.launcher_update_available') as object; + const locales = Locales.translate('notifications.launcher_update_available'); Notification.show({ title: locales['title'].replace('{from}', Launcher.version).replace('{to}', tag.tag), @@ -505,7 +505,7 @@ export default class State state = 'game-launch-available'; Notification.show({ - ...(Locales.translate('notifications.patch_repos_unavailable') as { title: string, body: string }), + ...Locales.translate('notifications.patch_repos_unavailable'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, importance: 'critical' }); diff --git a/src/ts/launcher/states/ApplyChanges.ts b/src/ts/launcher/states/ApplyChanges.ts index 7e5cf6c..6318925 100644 --- a/src/ts/launcher/states/ApplyChanges.ts +++ b/src/ts/launcher/states/ApplyChanges.ts @@ -21,7 +21,7 @@ export default (launcher: Launcher): Promise => { if (files.length > 0) { launcher.progressBar?.init({ - label: Locales.translate('launcher.progress.game.applying_changes') as string, + label: Locales.translate('launcher.progress.game.applying_changes'), showSpeed: false, showEta: true, showPercents: true, @@ -64,7 +64,7 @@ export default (launcher: Launcher): Promise => { if (patchErrors > 0) { - const locale = Locales.translate('notifications.game_changes_applying_error') as { title: string, body: string }; + const locale = Locales.translate<{ title: string, body: string }>('notifications.game_changes_applying_error'); Notification.show({ title: locale.title, diff --git a/src/ts/launcher/states/ApplyPatch.ts b/src/ts/launcher/states/ApplyPatch.ts index fee631a..b748193 100644 --- a/src/ts/launcher/states/ApplyPatch.ts +++ b/src/ts/launcher/states/ApplyPatch.ts @@ -12,7 +12,7 @@ export default (launcher: Launcher): Promise => { if (!await Package.exists('xdelta3')) { Notification.show({ - ...(Locales.translate('notifications.xdelta3_package_required') as { title: string, body: string }), + ...Locales.translate('notifications.xdelta3_package_required'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, importance: 'critical' }); @@ -61,7 +61,7 @@ export default (launcher: Launcher): Promise => { if (!result) { Notification.show({ - ...(Locales.translate('notifications.patch_applying_error') as { title: string, body: string }), + ...Locales.translate('notifications.patch_applying_error'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png` }); } @@ -73,7 +73,7 @@ export default (launcher: Launcher): Promise => { } }).catch(() => { Notification.show({ - ...(Locales.translate('notifications.patch_repos_unavailable') as { title: string, body: string }), + ...Locales.translate('notifications.patch_repos_unavailable'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, importance: 'critical' }); diff --git a/src/ts/launcher/states/Install.ts b/src/ts/launcher/states/Install.ts index 7abdd3a..8b3b1b6 100644 --- a/src/ts/launcher/states/Install.ts +++ b/src/ts/launcher/states/Install.ts @@ -29,7 +29,7 @@ export default (launcher: Launcher): Promise => { Game.update(prevGameVersion).then((stream) => { launcher.progressBar?.init({ - label: Locales.translate('launcher.progress.game.downloading') as string, + label: Locales.translate('launcher.progress.game.downloading'), showSpeed: true, showEta: true, showPercents: true, @@ -46,14 +46,14 @@ export default (launcher: Launcher): Promise => { { stream?.pauseDownload(); - launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.resume') as string; + launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.resume'); } else { stream?.resumeDownload(); - launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.pause') as string; + launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.pause'); } paused = !paused; @@ -67,7 +67,7 @@ export default (launcher: Launcher): Promise => { stream?.unpackStart(() => { launcher.progressBar?.init({ - label: Locales.translate('launcher.progress.game.unpacking') as string, + label: Locales.translate('launcher.progress.game.unpacking'), showSpeed: true, showEta: true, showPercents: true, diff --git a/src/ts/launcher/states/Launch.ts b/src/ts/launcher/states/Launch.ts index b488e8a..fda37a8 100644 --- a/src/ts/launcher/states/Launch.ts +++ b/src/ts/launcher/states/Launch.ts @@ -17,15 +17,17 @@ export default (launcher: Launcher): Promise => { Game.isTelemetryDisabled() .then(async (telemetryDisabled) => { // If telemetry servers are not disabled - if (!telemetryDisabled) + if (telemetryDisabled) { Notification.show({ - ...(Locales.translate('notifications.telemetry_not_disabled') as { title: string, body: string }), + ...Locales.translate('notifications.telemetry_not_disabled'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, importance: 'critical' }); debugThread.log('Telemetry is not disabled!'); + + resolve(); } // Otherwise run the game @@ -280,10 +282,12 @@ export default (launcher: Launcher): Promise => { }) .catch(() => { Notification.show({ - ...(Locales.translate('notifications.iputils_package_required') as { title: string, body: string }), + ...Locales.translate('notifications.iputils_package_required'), icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, importance: 'critical' }); + + resolve(); }); }); }; diff --git a/src/ts/launcher/states/RemoveOutdated.ts b/src/ts/launcher/states/RemoveOutdated.ts index 4786fa2..c07452e 100644 --- a/src/ts/launcher/states/RemoveOutdated.ts +++ b/src/ts/launcher/states/RemoveOutdated.ts @@ -18,7 +18,7 @@ export default (launcher: Launcher): Promise => { if (files.length > 0) { launcher.progressBar?.init({ - label: Locales.translate('launcher.progress.game.deleting_outdated') as string, + label: Locales.translate('launcher.progress.game.deleting_outdated'), showSpeed: false, showEta: true, showPercents: true,