2.0.0 beta 4

- added Discord RPC feature
- fixed `Cache.get()` hot cache debug output
This commit is contained in:
Observer KRypt0n_ 2022-01-04 18:26:36 +02:00
parent 66f852ddea
commit 34a48ed6a9
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
11 changed files with 143 additions and 67 deletions

View file

@ -6,6 +6,10 @@ splash:
- Paimon am ärgern...
- Versuche Yae zu ziehen...
# Launcher window
launcher:
predownload: Pre-download the game
# Einstellungs Fenster
settings:
# General

View file

@ -6,6 +6,10 @@ splash:
- Bullying Paimon...
- Pulling for Yae...
# Launcher window
launcher:
predownload: Pre-download the game
# Settings window
settings:
# General

View file

@ -6,6 +6,10 @@ splash:
- Издеваемся над Паймон...
- Пытаемся получить Яэ...
# Окна лаунчера
launcher:
predownload: Предзагрузить обновление
# Окно настроек
settings:
# Основное

View file

@ -77,9 +77,39 @@ promisify(async () => {
*/
enabled: false,
// todo
texts: {
idk: true
/**
* RPC settings
*/
fields: {
/**
* Launcher title
*/
title: 'An Anime Game Launcher',
/**
* Small messages after title
*/
state: {
/**
* Message showed when you're in game
*/
'in-launcher': 'Playing the game',
/**
* Message showed when you're in launcher
*/
'in-game': 'Preparing to launch'
},
/**
* RPC icon name
*/
icon: 'launcher',
/**
* Should it display amount of spent time or not
*/
timer: true
}
},

View file

@ -4,6 +4,7 @@
<script lang="ts">
import { onMount } from 'svelte';
import { _, locale } from 'svelte-i18n';
import Window from './ts/neutralino/Window';
@ -11,11 +12,21 @@
import constants from './ts/Constants';
import Game from './ts/Game';
import Background from './ts/launcher/Background';
import Archive from './ts/core/Archive';
import Debug from './ts/core/Debug';
import Downloader from './ts/core/Downloader';
import IPC from './ts/core/IPC';
import Gear from './assets/images/gear.png';
import GearActive from './assets/images/gear-active.png';
import Download from './assets/images/cloud-download.png';
import DiscordRPC from './ts/core/DiscordRPC';
constants.paths.launcherDir.then((dir) => {
Neutralino.filesystem.getStats(dir)
.catch(() => Neutralino.filesystem.createDirectory(dir));
});
const launcher = new Launcher(onMount);
Neutralino.events.on('ready', () => {
Window.open('splash', {
@ -27,12 +38,36 @@
});
});
constants.paths.launcherDir.then((dir) => {
Neutralino.filesystem.getStats(dir)
.catch(() => Neutralino.filesystem.createDirectory(dir));
});
Neutralino.events.on('windowClose', () => {
Downloader.closeStreams(true);
Archive.closeStreams(true);
const launcher = new Launcher(onMount);
constants.paths.launcherDir.then(async (path) => {
const time = new Date;
await IPC.purge();
if (launcher.rpc)
await launcher.rpc.stop(true);
Neutralino.filesystem.getStats(`${path}/logs`)
.then(() => saveLog())
.catch(async () => {
await Neutralino.filesystem.createDirectory(`${path}/logs`);
saveLog();
});
const saveLog = async () => {
const log = Debug.get().join("\r\n");
if (log != '')
await Neutralino.filesystem.writeFile(`${path}/logs/${time.getDate()}-${time.getMonth() + 1}-${time.getFullYear()}-${time.getHours()}-${time.getMinutes()}-${time.getSeconds()}.log`, log);
Neutralino.app.exit();
};
});
});
// Do some stuff when all the content will be loaded
onMount(() => {
@ -40,25 +75,9 @@
* Update launcher's title
*/
Game.latest.then((game) => {
Window.current.setTitle(`${constants.placeholders.uppercase.full} Linux Launcher - ${game.version}`);
Window.current.setTitle(`${constants.placeholders.uppercase.full} Linux Launcher - ${game.version} (beta revision)`);
});
/*const rpc = new DiscordRPC({
id: '901534333360304168',
details: 'Aboba',
state: 'Amogus',
icon: {
large: 'kleegame'
},
time: {
start: Math.round(Date.now() / 1000)
}
});
setTimeout(() => {
rpc.stop(true);
}, 10000);*/
/**
* Add some events to some elements
*/
@ -105,7 +124,7 @@
<img src={GearActive} class="active" alt="Settings">
</div>
<button class="button hint--left hint--small" aria-label="Pre-download the game" id="predownload">
<button class="button hint--left hint--small" aria-label="{typeof $locale === 'string' ? $_('launcher.predownload') : ''}" id="predownload">
<img src={Download} alt="Download" />
</button>

View file

@ -1,10 +1,5 @@
import '../i18n';
import App from '../index.svelte';
import constants from '../ts/Constants';
import Archive from '../ts/core/Archive';
import Debug from '../ts/core/Debug';
import Downloader from '../ts/core/Downloader';
import IPC from '../ts/core/IPC';
declare const Neutralino;
@ -12,34 +7,6 @@ Neutralino.init();
Neutralino.events.on('ready', () => import('../defaultSettings'));
Neutralino.events.on('windowClose', () => {
Downloader.closeStreams(true);
Archive.closeStreams(true);
constants.paths.launcherDir.then(async (path) => {
const time = new Date;
await IPC.purge();
Neutralino.filesystem.getStats(`${path}/logs`)
.then(() => saveLog())
.catch(async () => {
await Neutralino.filesystem.createDirectory(`${path}/logs`);
saveLog();
});
const saveLog = async () => {
const log = Debug.get().join("\r\n");
if (log != '')
await Neutralino.filesystem.writeFile(`${path}/logs/${time.getDate()}-${time.getMonth() + 1}-${time.getFullYear()}-${time.getHours()}-${time.getMinutes()}-${time.getSeconds()}.log`, log);
Neutralino.app.exit();
};
});
});
const app = new App({
target: document.getElementById('app')!
});

View file

@ -8,16 +8,20 @@ import ProgressBar from './launcher/ProgressBar';
import State from './launcher/State';
import Debug from './core/Debug';
import IPC from './core/IPC';
import DiscordRPC from './core/DiscordRPC';
export default class Launcher
{
public state?: State;
public progressBar?: ProgressBar;
public rpc?: DiscordRPC;
protected settingsMenu?: Process;
public constructor(onMount)
{
this.updateDiscordRPC('in-launcher');
onMount(() => {
this.progressBar = new ProgressBar(this);
this.state = new State(this);
@ -38,7 +42,7 @@ export default class Launcher
title: 'Settings',
width: 900,
height: 600,
enableInspector: true,
// enableInspector: true,
exitProcessOnClose: false
});
@ -83,4 +87,43 @@ export default class Launcher
resolve(`https://${constants.placeholders.lowercase.first}.${constants.placeholders.lowercase.company}.com/launcher/10/${await Configs.get('lang.launcher')}?api_url=https%3A%2F%2Fapi-os-takumi.${constants.placeholders.lowercase.company}.com%2Fhk4e_global&key=gcStgarh&prev=false`);
});
}
/**
* Update Discord RPC notification if it is enabled
*/
public updateDiscordRPC(state: 'in-launcher' | 'in-game'): Promise<void>
{
return new Promise((resolve) => {
Configs.get('discord').then((discord) => {
// @ts-expect-error
if (discord.enabled)
{
if (this.rpc)
this.rpc.stop(true);
this.rpc = new DiscordRPC({
id: '901534333360304168',
// @ts-expect-error
details: discord.fields.title,
// @ts-expect-error
state: discord.fields.state[state],
icon: {
// @ts-expect-error
large: discord.fields.icon
},
time: {
// @ts-expect-error
start: discord.fields.time ? Math.round(Date.now() / 1000) : 0
}
});
resolve();
}
});
});
}
};

View file

@ -29,7 +29,7 @@ export default class Cache
message: [
`Resolved ${this.cache[name].expired ? 'expired' : 'unexpired'} hot cache record`,
`[name] ${name}`,
`[value]: ${this.cache[name].value}`
`[value]: ${JSON.stringify(this.cache[name].value)}`
]
});

View file

@ -1,6 +1,7 @@
import Process from '../neutralino/Process';
import type { Params } from '../types/DiscordRPC';
import Process from '../neutralino/Process';
declare const NL_CWD;
export default class DiscordRPC
@ -49,8 +50,6 @@ export default class DiscordRPC
*/
public stop(forced: boolean = false): Promise<void>
{
console.log(this.process);
return this.process!.kill(forced);
}
};

View file

@ -1,3 +1,5 @@
import type Launcher from '../../Launcher';
import Configs from '../../Configs';
import constants from '../../Constants';
import { DebugThread } from '../../core/Debug';
@ -11,7 +13,7 @@ import Baal from '../../../assets/images/baal64-transparent.png';
declare const Neutralino;
export default (): Promise<void> => {
export default (launcher: Launcher): Promise<void> => {
return new Promise(async (resolve) => {
const debugThread = new DebugThread('State/Launch', 'Starting the game');
@ -35,6 +37,8 @@ export default (): Promise<void> => {
{
Window.current.hide();
launcher.updateDiscordRPC('in-game');
/**
* Selecting wine executable
*/
@ -128,6 +132,8 @@ export default (): Promise<void> => {
Window.current.show();
launcher.updateDiscordRPC('in-launcher');
// TODO
resolve();

View file

@ -191,7 +191,7 @@ class Process
}
// Set output redirection to the temp file
command = `${command} > "${this.addSlashes(tmpFile)}" 2>&1 </dev/null`;
command = `${command} > "${this.addSlashes(tmpFile)}" 2>&1 &`;
// Set current working directory
if (options.cwd)