Add Discord RPC, disable Voice Pack Selection

This commit is contained in:
Maroxy 2021-10-23 20:59:26 +02:00
parent 35f5d5c04e
commit fd6558408c
7 changed files with 1705 additions and 1480 deletions

View file

@ -90,6 +90,10 @@ app.whenReady().then(() => {
ipcMain.on('updateVP', (event, args) => {
mainWindow.webContents.send('updateVP', { 'oldvp': args.oldvp });
});
ipcMain.on('rpcstate', (event, args) => {
mainWindow.webContents.send('rpcstate', {});
});
});
// Quit when all windows are closed, except on macOS. There, it's common

View file

@ -45,6 +45,7 @@
},
"dependencies": {
"cash-dom": "^8.1.0",
"discord-rpc": "^4.0.1",
"follow-redirects": "^1.14.4"
}
}

View file

@ -24,7 +24,7 @@
<div class="settings-item" id="general">
<h2 i18id="GeneralSettings">General</h2>
<hr>
<p i18id="Langs">Language</p>
<h3 i18id="Langs">Language</h3>
<select class="dropdown-menu" id="language-list">
<option value="en-us">English (US)</option>
<option value="zh-cn">中文(简化)(Chinese Simplified)</option>
@ -41,14 +41,17 @@
<option value="vi-vn">Tiếng Việt (Vietnamese)</option>
</select>
<br>
<p i18id="Voice">Voice Pack</p>
<select class="dropdown-menu" id="voice-list">
<h3 i18id="Voice">Voice Pack</h3>
<select class="dropdown-menu" id="voice-list" disabled>
<option value="en-us">English (US)</option>
<option value="zh-cn">汉语 (Chinese)</option>
<option value="ja-jp">日本語 (Japanese)</option>
<option value="ko-kr">한국어 (Korean)</option>
</select>
<br>
<h3>Discord RPC</h3>
<input type="checkbox" id="drpc" name="drpc">
<br>
</div>
<hr>
<div class="settings-item" id="runners">

View file

@ -35,7 +35,8 @@ type Config = {
name: string,
folder: string,
executable: string
}
},
rpc: boolean
};
export class Genshinlib
@ -94,7 +95,8 @@ export class Genshinlib
},
version: null,
patch: null,
runner: null
runner: null,
rpc: false
}, null, 4));
return JSON.parse(fs.readFileSync(this.launcherJson));

View file

@ -1,7 +1,9 @@
const path = require('path');
const fs = require('fs');
const discordrpc = require("discord-rpc");
const { exec } = require('child_process');
const { ipcRenderer } = require('electron');
let rpc: any;
import $ from 'cash-dom';
import i18n from './i18n';
@ -19,6 +21,20 @@ $(() => {
if (Genshinlib.version !== null)
document.title = 'Genshin Impact Linux Launcher - ' + Genshinlib.version;
if (Genshinlib.getConfig().rpc) {
rpc = new discordrpc.Client({ transport: "ipc" });
rpc.login({ clientId: '901534333360304168' }).catch(console.error);
rpc.on('ready', () => {
rpc.setActivity({
details: `Preparing to launch`,
largeImageKey: `launcher`,
largeImageText: `An Anime Game Launcher`,
instance: false,
});
});
}
LauncherUI.setState('game-launch-available');
ipcRenderer.on('changelang', (event: void, data: any) => {
@ -27,6 +43,34 @@ $(() => {
LauncherUI.setState(LauncherUI.launcherState);
});
ipcRenderer.on('rpcstate', (event: void, data: any) => {
if(!rpc) {
rpc = new discordrpc.Client({ transport: "ipc" });
rpc.login({ clientId: '901534333360304168' }).catch(console.error);
rpc.on('ready', () => {
rpc.setActivity({
details: `Preparing to launch`,
largeImageKey: `launcher`,
largeImageText: `An Anime Game Launcher`,
instance: false,
});
});
if (!Genshinlib.getConfig().rpc)
Genshinlib.updateConfig({
rpc: true
});
} else {
rpc.clearActivity();
rpc.destroy();
rpc = false;
Genshinlib.updateConfig({
rpc: false
});
}
});
ipcRenderer.on('updateVP', (event: void, remotedata: any) => {
Genshinlib.getData().then(data => {
LauncherUI.initProgressBar();
@ -185,6 +229,15 @@ $(() => {
console.log(`Wine executable: ${wineExeutable}`);
if (rpc)
rpc.setActivity({
details: `In-Game`,
largeImageKey: `game`,
largeImageText: `An Anime Game Launcher`,
startTimestamp: parseInt(new Date().setDate(new Date().getDate()).toString()),
instance: false,
});
exec(`${wineExeutable} launcher.bat`, {
cwd: Genshinlib.gameDir,
env: {
@ -196,6 +249,14 @@ $(() => {
ipcRenderer.invoke('show-window');
if (rpc)
rpc.setActivity({
details: `Preparing to launch`,
largeImageKey: `launcher`,
largeImageText: `An Anime Game Launcher`,
instance: false,
});
console.log(err);
console.log(stdout);
console.log(stderr);

View file

@ -28,8 +28,21 @@ $(() => {
// Select the saved options in launcher.json on load.
$(`#voice-list option[value="${Genshinlib.getConfig().lang.voice}"]`).prop('selected', true);
if (Genshinlib.getConfig().rpc)
$(`#drpc`).prop('checked', true);
$(`#language-list option[value="${Genshinlib.getConfig().lang.launcher}"]`).prop('selected', true);
$('#drpc').on('change', (e) => {
if ($("#drpc").is(':checked'))
{
ipcRenderer.send('rpcstate', {});
}
else
{
ipcRenderer.send('rpcstate', {});
}
})
$('#voice-list').on('change', (e) => {
let activeVP = Genshinlib.getConfig().lang.voice;

3091
yarn.lock

File diff suppressed because it is too large Load diff