fix(discord): fixed an issue where timeChanged was not being applied to Discord activities (#1290)

This commit is contained in:
JellyBrick
2023-10-09 19:36:06 +09:00
committed by GitHub
parent 7ca4dc5c85
commit 7693a3ba4a

View File

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