diff --git a/package.json b/package.json index 8b86706..19007c9 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ } }, "devDependencies": { + "@types/discord-rpc": "^4.0.0", "electron": "^14.0.0", "electron-builder": "^22.13.1", "sass": "^1.41.0", diff --git a/src/ts/index.ts b/src/ts/index.ts index 0584aa8..aba80b1 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -40,8 +40,8 @@ $(() => { ipcRenderer.on('rpc-toggle', () => { DiscordRPC.isActive() ? - DiscordRPC.init() : - DiscordRPC.close(); + DiscordRPC.close() : + DiscordRPC.init(); }); // FIXME @@ -208,7 +208,8 @@ $(() => { DiscordRPC.setActivity({ details: 'In-Game', largeImageKey: 'game', - largeImageText: 'An Anime Game Launcher' + largeImageText: 'An Anime Game Launcher', + startTimestamp: new Date().setDate(new Date().getDate()) }); } diff --git a/src/ts/lib/DiscordRPC.ts b/src/ts/lib/DiscordRPC.ts index c43296b..0eb18e9 100644 --- a/src/ts/lib/DiscordRPC.ts +++ b/src/ts/lib/DiscordRPC.ts @@ -1,4 +1,4 @@ -const discordRpc = require('discord-rpc'); +import discordRpc, { Client, Presence } from 'discord-rpc'; export class DiscordRPC { @@ -8,7 +8,7 @@ export class DiscordRPC public static init () { - this.rpc = new discordRpc.Client({ transport: 'ipc' }); + this.rpc = new discordRpc.Client({ transport: 'ipc' }) as Client; this.rpc.login({ clientId: this.clientId }).catch(console.error); @@ -16,18 +16,18 @@ export class DiscordRPC this.rpc.setActivity({ details: 'Preparing to launch', largeImageKey: 'launcher', - largeImageText: 'An Anime Game Launcher', - instance: false + largeImageText: 'An Anime Game Launcher' }); }); } - public static setActivity (activity: any): void + public static setActivity (activity: Presence): void { - this.rpc?.setActivity({ - startTimestamp: parseInt(new Date().setDate(new Date().getDate()).toString()), - instance: false, - ...activity + this.rpc.setActivity({ + ...activity, + ...{ + instance: false + } }); } @@ -38,9 +38,9 @@ export class DiscordRPC public static close (): void { - this.rpc?.clearActivity(); - this.rpc?.destroy(); + this.rpc.clearActivity(); + this.rpc.destroy(); - this.rpc = null; + this.rpc = null as any; } }