mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-24 02:28:15 +03:00
Push
This commit is contained in:
parent
0cde3979bf
commit
25d1a0e6cd
3 changed files with 35 additions and 29 deletions
|
@ -13,12 +13,20 @@ type LauncherState =
|
||||||
export class LauncherUI
|
export class LauncherUI
|
||||||
{
|
{
|
||||||
protected static _launcherState: LauncherState = 'game-launch-available';
|
protected static _launcherState: LauncherState = 'game-launch-available';
|
||||||
|
protected static _i18n: any;
|
||||||
|
|
||||||
public static get launcherState(): LauncherState
|
public static get launcherState(): LauncherState
|
||||||
{
|
{
|
||||||
return this._launcherState;
|
return this._launcherState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static get i18n(): any
|
||||||
|
{
|
||||||
|
if (!this._i18n)
|
||||||
|
this._i18n = i18n;
|
||||||
|
return this._i18n;
|
||||||
|
}
|
||||||
|
|
||||||
public static setState (state: LauncherState)
|
public static setState (state: LauncherState)
|
||||||
{
|
{
|
||||||
$('#downloader-panel').css('display', 'none');
|
$('#downloader-panel').css('display', 'none');
|
||||||
|
@ -27,40 +35,40 @@ export class LauncherUI
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case 'patch-unavailable':
|
case 'patch-unavailable':
|
||||||
$('#launch').text(i18n.translate('PatchRequired'));
|
$('#launch').text(this.i18n.translate('PatchRequired'));
|
||||||
$('#launch').attr('disabled', 'disabled');
|
$('#launch').attr('disabled', 'disabled');
|
||||||
|
|
||||||
$('#launch').addClass('hint--top')
|
$('#launch').addClass('hint--top')
|
||||||
.addClass('hint--medium');
|
.addClass('hint--medium');
|
||||||
|
|
||||||
$('#launch').attr('data-hint', i18n.translate('PatchRequiredHint'));
|
$('#launch').attr('data-hint', this.i18n.translate('PatchRequiredHint'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'test-patch-available':
|
case 'test-patch-available':
|
||||||
$('#launch').text(i18n.translate('TestPatch'));
|
$('#launch').text(this.i18n.translate('TestPatch'));
|
||||||
|
|
||||||
$('#launch').addClass('button-blue')
|
$('#launch').addClass('button-blue')
|
||||||
.addClass('hint--top')
|
.addClass('hint--top')
|
||||||
.addClass('hint--large');
|
.addClass('hint--large');
|
||||||
|
|
||||||
$('#launch').attr('data-hint', i18n.translate('TestPatchHint'));
|
$('#launch').attr('data-hint', this.i18n.translate('TestPatchHint'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'patch-applying':
|
case 'patch-applying':
|
||||||
$('#launch').text(i18n.translate('ApplyPatch'));
|
$('#launch').text(this.i18n.translate('ApplyPatch'));
|
||||||
$('#launch').attr('disabled', 'disabled');
|
$('#launch').attr('disabled', 'disabled');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'game-update-available':
|
case 'game-update-available':
|
||||||
$('#launch').text(i18n.translate('Update'));
|
$('#launch').text(this.i18n.translate('Update'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'game-installation-available':
|
case 'game-installation-available':
|
||||||
$('#launch').text(i18n.translate('Install'));
|
$('#launch').text(this.i18n.translate('Install'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -73,7 +81,7 @@ export class LauncherUI
|
||||||
.removeClass('hint--medium')
|
.removeClass('hint--medium')
|
||||||
.removeClass('hint--large');
|
.removeClass('hint--large');
|
||||||
|
|
||||||
$('#launch').text(i18n.translate('Launch'));
|
$('#launch').text(this.i18n.translate('Launch'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -172,10 +180,12 @@ export class LauncherUI
|
||||||
public static updateLang (lang: string|null = null): void
|
public static updateLang (lang: string|null = null): void
|
||||||
{
|
{
|
||||||
if (lang !== null)
|
if (lang !== null)
|
||||||
i18n.setLang(lang);
|
this.i18n.setLang(lang);
|
||||||
|
|
||||||
|
console.log(this.i18n.loadedLanguage);
|
||||||
|
|
||||||
$('*[i18id]').each((i, element) => {
|
$('*[i18id]').each((i, element) => {
|
||||||
element.innerText = i18n.translate(element.getAttribute('i18id')!);
|
element.innerText = this.i18n.translate(element.getAttribute('i18id')!);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,9 +3,7 @@ const fs = require('fs');
|
||||||
const discordrpc = require("discord-rpc");
|
const discordrpc = require("discord-rpc");
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { ipcRenderer } = require('electron');
|
const { ipcRenderer } = require('electron');
|
||||||
|
|
||||||
import $ from 'cash-dom';
|
import $ from 'cash-dom';
|
||||||
import { i18n } from './i18n';
|
|
||||||
|
|
||||||
import { Genshinlib } from './Genshinlib';
|
import { Genshinlib } from './Genshinlib';
|
||||||
import { LauncherUI } from './LauncherUI';
|
import { LauncherUI } from './LauncherUI';
|
||||||
|
@ -23,17 +21,16 @@ $(() => {
|
||||||
if (Genshinlib.version !== null)
|
if (Genshinlib.version !== null)
|
||||||
document.title = 'Genshin Impact Linux Launcher - ' + Genshinlib.version;
|
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) => {
|
ipcRenderer.on('change-lang', (event: void, data: any) => {
|
||||||
LauncherUI.updateBackground();
|
LauncherUI.updateBackground();
|
||||||
LauncherUI.updateSocial();
|
LauncherUI.updateSocial();
|
||||||
// Needs data.lang in the arguments since the button doesn't get updated otherwise.
|
|
||||||
LauncherUI.updateLang(data.lang);
|
LauncherUI.updateLang(data.lang);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
LauncherUI.setState('game-launch-available');
|
||||||
|
LauncherUI.updateBackground();
|
||||||
|
LauncherUI.updateSocial();
|
||||||
|
|
||||||
let rpc: any;
|
let rpc: any;
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
@ -117,14 +114,14 @@ $(() => {
|
||||||
|
|
||||||
// For some reason this keeps breaking and locking up most of the time.
|
// 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) => {
|
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(() => {
|
}).then(() => {
|
||||||
console.log(`%c> Unpacking voice data...`, 'font-size: 16px');
|
console.log(`%c> Unpacking voice data...`, 'font-size: 16px');
|
||||||
|
|
||||||
LauncherUI.initProgressBar();
|
LauncherUI.initProgressBar();
|
||||||
|
|
||||||
Genshinlib.unzip(path.join(Genshinlib.launcherDir, voicePack.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
|
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(() => {
|
}).then(() => {
|
||||||
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
|
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
|
||||||
LauncherUI.setState('game-launch-available');
|
LauncherUI.setState('game-launch-available');
|
||||||
|
@ -203,7 +200,7 @@ $(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launching game
|
// Launching game
|
||||||
if ($('#launch').text() == i18n.translate('Launch'))
|
if ($('#launch').text() == LauncherUI.i18n.translate('Launch'))
|
||||||
{
|
{
|
||||||
console.log(`%c> Starting the game...`, 'font-size: 16px');
|
console.log(`%c> Starting the game...`, 'font-size: 16px');
|
||||||
|
|
||||||
|
@ -286,7 +283,7 @@ $(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply test patch
|
// 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');
|
console.log(`%c> Applying patch...`, 'font-size: 16px');
|
||||||
|
|
||||||
|
@ -326,7 +323,7 @@ $(() => {
|
||||||
LauncherUI.initProgressBar();
|
LauncherUI.initProgressBar();
|
||||||
|
|
||||||
Genshinlib.downloadFile(diff.path, path.join(Genshinlib.launcherDir, diff.name), (current: number, total: number, difference: number) => {
|
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(() => {
|
}).then(() => {
|
||||||
/**
|
/**
|
||||||
* Unpacking downloaded game
|
* Unpacking downloaded game
|
||||||
|
@ -340,7 +337,7 @@ $(() => {
|
||||||
LauncherUI.initProgressBar();
|
LauncherUI.initProgressBar();
|
||||||
|
|
||||||
Genshinlib.unzip(path.join(Genshinlib.launcherDir, diff.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
|
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(() => {
|
}).then(() => {
|
||||||
/**
|
/**
|
||||||
* Downloading voice data
|
* Downloading voice data
|
||||||
|
@ -363,7 +360,7 @@ $(() => {
|
||||||
LauncherUI.initProgressBar();
|
LauncherUI.initProgressBar();
|
||||||
|
|
||||||
Genshinlib.downloadFile(voicePack.path, path.join(Genshinlib.launcherDir, voicePack.name), (current: number, total: number, difference: number) => {
|
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(() => {
|
}).then(() => {
|
||||||
/**
|
/**
|
||||||
* Unpacking downloaded game
|
* Unpacking downloaded game
|
||||||
|
@ -374,7 +371,7 @@ $(() => {
|
||||||
LauncherUI.initProgressBar();
|
LauncherUI.initProgressBar();
|
||||||
|
|
||||||
Genshinlib.unzip(path.join(Genshinlib.launcherDir, voicePack.name), Genshinlib.gameDir, (current: number, total: number, difference: number) => {
|
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(() => {
|
}).then(() => {
|
||||||
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
|
fs.unlinkSync(path.join(Genshinlib.launcherDir, voicePack.name));
|
||||||
|
|
||||||
|
@ -390,14 +387,14 @@ $(() => {
|
||||||
console.log(`%c> Applying patch...`, 'font-size: 16px');
|
console.log(`%c> Applying patch...`, 'font-size: 16px');
|
||||||
|
|
||||||
// patch-applying state changes only button text
|
// patch-applying state changes only button text
|
||||||
$('#downloaded').text(i18n.translate('ApplyPatch'));
|
$('#downloaded').text(LauncherUI.i18n.translate('ApplyPatch'));
|
||||||
|
|
||||||
Genshinlib.patchGame(data.game.latest.version, () => {
|
Genshinlib.patchGame(data.game.latest.version, () => {
|
||||||
LauncherUI.setState('game-launch-available');
|
LauncherUI.setState('game-launch-available');
|
||||||
|
|
||||||
ipcRenderer.send('notification', {
|
ipcRenderer.send('notification', {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
body: i18n.translate('GameDownloaded')
|
body: LauncherUI.i18n.translate('GameDownloaded')
|
||||||
});
|
});
|
||||||
}, (data) => console.log(data.toString()));
|
}, (data) => console.log(data.toString()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,13 @@ const { ipcRenderer } = require('electron');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
import $ from 'cash-dom';
|
import $ from 'cash-dom';
|
||||||
import { i18n } from './i18n';
|
|
||||||
import { Genshinlib } from './Genshinlib';
|
import { Genshinlib } from './Genshinlib';
|
||||||
import { LauncherUI } from './LauncherUI';
|
import { LauncherUI } from './LauncherUI';
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
|
|
||||||
$('*[i18id]').each((i, element) => {
|
$('*[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) => {
|
$('.menu-item').on('click', (e) => {
|
||||||
|
|
Loading…
Reference in a new issue