This commit is contained in:
Maroxy 2021-10-24 10:27:29 +02:00
parent 0cde3979bf
commit 25d1a0e6cd
3 changed files with 35 additions and 29 deletions

View file

@ -13,12 +13,20 @@ type LauncherState =
export class LauncherUI
{
protected static _launcherState: LauncherState = 'game-launch-available';
protected static _i18n: any;
public static get launcherState(): LauncherState
{
return this._launcherState;
}
public static get i18n(): any
{
if (!this._i18n)
this._i18n = i18n;
return this._i18n;
}
public static setState (state: LauncherState)
{
$('#downloader-panel').css('display', 'none');
@ -27,40 +35,40 @@ export class LauncherUI
switch (state)
{
case 'patch-unavailable':
$('#launch').text(i18n.translate('PatchRequired'));
$('#launch').text(this.i18n.translate('PatchRequired'));
$('#launch').attr('disabled', 'disabled');
$('#launch').addClass('hint--top')
.addClass('hint--medium');
$('#launch').attr('data-hint', i18n.translate('PatchRequiredHint'));
$('#launch').attr('data-hint', this.i18n.translate('PatchRequiredHint'));
break;
case 'test-patch-available':
$('#launch').text(i18n.translate('TestPatch'));
$('#launch').text(this.i18n.translate('TestPatch'));
$('#launch').addClass('button-blue')
.addClass('hint--top')
.addClass('hint--large');
$('#launch').attr('data-hint', i18n.translate('TestPatchHint'));
$('#launch').attr('data-hint', this.i18n.translate('TestPatchHint'));
break;
case 'patch-applying':
$('#launch').text(i18n.translate('ApplyPatch'));
$('#launch').text(this.i18n.translate('ApplyPatch'));
$('#launch').attr('disabled', 'disabled');
break;
case 'game-update-available':
$('#launch').text(i18n.translate('Update'));
$('#launch').text(this.i18n.translate('Update'));
break;
case 'game-installation-available':
$('#launch').text(i18n.translate('Install'));
$('#launch').text(this.i18n.translate('Install'));
break;
@ -73,7 +81,7 @@ export class LauncherUI
.removeClass('hint--medium')
.removeClass('hint--large');
$('#launch').text(i18n.translate('Launch'));
$('#launch').text(this.i18n.translate('Launch'));
break;
}
@ -172,10 +180,12 @@ export class LauncherUI
public static updateLang (lang: string|null = null): void
{
if (lang !== null)
i18n.setLang(lang);
this.i18n.setLang(lang);
console.log(this.i18n.loadedLanguage);
$('*[i18id]').each((i, element) => {
element.innerText = i18n.translate(element.getAttribute('i18id')!);
element.innerText = this.i18n.translate(element.getAttribute('i18id')!);
});
}
}

View file

@ -3,9 +3,7 @@ const fs = require('fs');
const discordrpc = require("discord-rpc");
const { exec } = require('child_process');
const { ipcRenderer } = require('electron');
import $ from 'cash-dom';
import { i18n } from './i18n';
import { Genshinlib } from './Genshinlib';
import { LauncherUI } from './LauncherUI';
@ -23,17 +21,16 @@ $(() => {
if (Genshinlib.version !== null)
document.title = 'Genshin Impact Linux Launcher - ' + Genshinlib.version;
LauncherUI.setState('game-launch-available');
LauncherUI.updateBackground();
LauncherUI.updateSocial();
ipcRenderer.on('change-lang', (event: void, data: any) => {
LauncherUI.updateBackground();
LauncherUI.updateSocial();
// Needs data.lang in the arguments since the button doesn't get updated otherwise.
LauncherUI.updateLang(data.lang);
});
LauncherUI.setState('game-launch-available');
LauncherUI.updateBackground();
LauncherUI.updateSocial();
let rpc: any;
// FIXME
@ -117,14 +114,14 @@ $(() => {
// For some reason this keeps breaking and locking up most of the time.
Genshinlib.downloadFile(voicePack.path, path.join(Genshinlib.launcherDir, voicePack.name), (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Downloading'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Downloading'), current, total, difference);
}).then(() => {
console.log(`%c> Unpacking voice data...`, 'font-size: 16px');
LauncherUI.initProgressBar();
Genshinlib.unzip(path.join(Genshinlib.launcherDir, voicePack.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Unpack'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Unpack'), current, total, difference);
}).then(() => {
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
LauncherUI.setState('game-launch-available');
@ -203,7 +200,7 @@ $(() => {
}
// Launching game
if ($('#launch').text() == i18n.translate('Launch'))
if ($('#launch').text() == LauncherUI.i18n.translate('Launch'))
{
console.log(`%c> Starting the game...`, 'font-size: 16px');
@ -286,7 +283,7 @@ $(() => {
}
// Apply test patch
else if ($('#launch').text() == i18n.translate('TestPatch'))
else if ($('#launch').text() == LauncherUI.i18n.translate('TestPatch'))
{
console.log(`%c> Applying patch...`, 'font-size: 16px');
@ -326,7 +323,7 @@ $(() => {
LauncherUI.initProgressBar();
Genshinlib.downloadFile(diff.path, path.join(Genshinlib.launcherDir, diff.name), (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Downloading'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Downloading'), current, total, difference);
}).then(() => {
/**
* Unpacking downloaded game
@ -340,7 +337,7 @@ $(() => {
LauncherUI.initProgressBar();
Genshinlib.unzip(path.join(Genshinlib.launcherDir, diff.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Unpack'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Unpack'), current, total, difference);
}).then(() => {
/**
* Downloading voice data
@ -363,7 +360,7 @@ $(() => {
LauncherUI.initProgressBar();
Genshinlib.downloadFile(voicePack.path, path.join(Genshinlib.launcherDir, voicePack.name), (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Downloading'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Downloading'), current, total, difference);
}).then(() => {
/**
* Unpacking downloaded game
@ -374,7 +371,7 @@ $(() => {
LauncherUI.initProgressBar();
Genshinlib.unzip(path.join(Genshinlib.launcherDir, voicePack.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
LauncherUI.updateProgressBar(i18n.translate('Unpack'), current, total, difference);
LauncherUI.updateProgressBar(LauncherUI.i18n.translate('Unpack'), current, total, difference);
}).then(() => {
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
@ -390,14 +387,14 @@ $(() => {
console.log(`%c> Applying patch...`, 'font-size: 16px');
// patch-applying state changes only button text
$('#downloaded').text(i18n.translate('ApplyPatch'));
$('#downloaded').text(LauncherUI.i18n.translate('ApplyPatch'));
Genshinlib.patchGame(data.game.latest.version, () => {
LauncherUI.setState('game-launch-available');
ipcRenderer.send('notification', {
title: document.title,
body: i18n.translate('GameDownloaded')
body: LauncherUI.i18n.translate('GameDownloaded')
});
}, (data) => console.log(data.toString()));
}

View file

@ -4,14 +4,13 @@ const { ipcRenderer } = require('electron');
const { exec } = require('child_process');
import $ from 'cash-dom';
import { i18n } from './i18n';
import { Genshinlib } from './Genshinlib';
import { LauncherUI } from './LauncherUI';
$(() => {
$('*[i18id]').each((i, element) => {
element.innerText = i18n.translate(element.getAttribute('i18id')?.toString()!);
element.innerText = LauncherUI.i18n.translate(element.getAttribute('i18id')?.toString()!);
});
$('.menu-item').on('click', (e) => {