From 7693a3ba4ad3ff459352884eee8509e23cc54061 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 9 Oct 2023 19:36:06 +0900 Subject: [PATCH] fix(discord): fixed an issue where `timeChanged` was not being applied to Discord activities (#1290) --- plugins/discord/back.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/discord/back.ts b/plugins/discord/back.ts index 454290a7..baeeb33b 100644 --- a/plugins/discord/back.ts +++ b/plugins/discord/back.ts @@ -1,4 +1,4 @@ -import { app, dialog } from 'electron'; +import { app, dialog, ipcMain } from 'electron'; import { Client as DiscordClient } from '@xhayper/discord-rpc'; import { dev } from 'electron-is'; @@ -188,8 +188,22 @@ export default ( // If the page is ready, register the callback win.once('ready-to-show', () => { - registerCallback(updateActivity); + let lastSongInfo: SongInfo; + registerCallback((songInfo) => { + lastSongInfo = songInfo; + updateActivity(songInfo); + }); connect(); + let lastSent = Date.now(); + ipcMain.on('timeChanged', (_, t: number) => { + const currentTime = Date.now(); + // if lastSent is more than 5 seconds ago, send the new time + if (currentTime - lastSent > 5000) { + lastSent = currentTime; + lastSongInfo.elapsedSeconds = t; + updateActivity(lastSongInfo); + } + }); }); app.on('window-all-closed', clear); };