Skip to content

Commit

Permalink
fix(discord): fixed an issue where timeChanged was not being applie…
Browse files Browse the repository at this point in the history
…d to Discord activities (#1290)
  • Loading branch information
JellyBrick authored Oct 9, 2023
1 parent 7ca4dc5 commit 7693a3b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions plugins/discord/back.ts
Original file line number Diff line number Diff line change
@@ -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';

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

0 comments on commit 7693a3b

Please sign in to comment.