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); };