fix: callback for time-changed event (#2577)

Co-authored-by: Derek Alsop <15299183+Azorant@users.noreply.github.com>
This commit is contained in:
JellyBrick
2024-11-03 19:18:06 +09:00
committed by GitHub
parent 516fbff3d7
commit 1e4cd699db
13 changed files with 137 additions and 91 deletions

View File

@ -28,18 +28,6 @@ export default createPlugin({
},
backend: {
liteMode: false,
data: {
cover: '',
cover_url: '',
title: '',
artists: [] as string[],
status: '',
progress: 0,
duration: 0,
album_url: '',
album: undefined,
url: '',
} as Data,
start({ ipc }) {
const secToMilisec = (t: number) => Math.round(Number(t) * 1e3);
@ -85,31 +73,24 @@ export default createPlugin({
ipc.on('ytmd:player-api-loaded', () =>
ipc.send('ytmd:setup-time-changed-listener'),
);
ipc.on('ytmd:time-changed', (t: number) => {
if (!this.data.title) {
return;
}
this.data.progress = secToMilisec(t);
post(this.data);
});
registerCallback((songInfo) => {
if (!songInfo.title && !songInfo.artist) {
return;
}
this.data.duration = secToMilisec(songInfo.songDuration);
this.data.progress = secToMilisec(songInfo.elapsedSeconds ?? 0);
this.data.cover = songInfo.imageSrc ?? '';
this.data.cover_url = songInfo.imageSrc ?? '';
this.data.album_url = songInfo.imageSrc ?? '';
this.data.title = songInfo.title;
this.data.artists = [songInfo.artist];
this.data.status = songInfo.isPaused ? 'stopped' : 'playing';
this.data.album = songInfo.album;
this.data.url = songInfo.url ?? '';
post(this.data);
post({
duration: secToMilisec(songInfo.songDuration),
progress: secToMilisec(songInfo.elapsedSeconds ?? 0),
cover: songInfo.imageSrc ?? '',
cover_url: songInfo.imageSrc ?? '',
album_url: songInfo.imageSrc ?? '',
title: songInfo.title,
artists: [songInfo.artist],
status: songInfo.isPaused ? 'stopped' : 'playing',
album: songInfo.album,
url: songInfo.url ?? '',
});
});
},
},