mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
fix(discord): fixed an issue where timeChanged was not being applied to Discord activities (#1290)
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { app, dialog } from 'electron';
|
import { app, dialog, ipcMain } from 'electron';
|
||||||
import { Client as DiscordClient } from '@xhayper/discord-rpc';
|
import { Client as DiscordClient } from '@xhayper/discord-rpc';
|
||||||
import { dev } from 'electron-is';
|
import { dev } from 'electron-is';
|
||||||
|
|
||||||
@ -188,8 +188,22 @@ export default (
|
|||||||
|
|
||||||
// If the page is ready, register the callback
|
// If the page is ready, register the callback
|
||||||
win.once('ready-to-show', () => {
|
win.once('ready-to-show', () => {
|
||||||
registerCallback(updateActivity);
|
let lastSongInfo: SongInfo;
|
||||||
|
registerCallback((songInfo) => {
|
||||||
|
lastSongInfo = songInfo;
|
||||||
|
updateActivity(songInfo);
|
||||||
|
});
|
||||||
connect();
|
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);
|
app.on('window-all-closed', clear);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user