mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix song-info-request
This commit is contained in:
@ -19,16 +19,24 @@ module.exports = () => {
|
||||
apiEvent.detail.addEventListener('videodatachange', (name, _dataEvent) => {
|
||||
if (name !== 'dataloaded') return;
|
||||
video.dispatchEvent(srcChangedEvent);
|
||||
ipcRenderer.send("video-src-changed", JSON.stringify(apiEvent.detail.getPlayerResponse()));
|
||||
sendSongInfo();
|
||||
})
|
||||
for (const status of ['playing', 'pause']) {
|
||||
video.addEventListener(status, sendSongInfo);
|
||||
}
|
||||
|
||||
video.addEventListener('pause', e => {
|
||||
ipcRenderer.send("playPaused", { isPaused: true, elapsedSeconds: Math.floor(e.target.currentTime) });
|
||||
});
|
||||
|
||||
video.addEventListener('playing', e => {
|
||||
if (e.target.currentTime > 0){
|
||||
ipcRenderer.send("playPaused", { isPaused: false, elapsedSeconds: Math.floor(e.target.currentTime) });
|
||||
}
|
||||
});
|
||||
|
||||
function sendSongInfo() {
|
||||
const data = apiEvent.detail.getPlayerResponse();
|
||||
data.videoDetails.elapsedSeconds = Math.floor(video.currentTime);
|
||||
data.videoDetails.isPaused = video.paused;
|
||||
ipcRenderer.send("song-info-request", JSON.stringify(apiEvent.detail.getPlayerResponse()));
|
||||
ipcRenderer.send("video-src-changed", JSON.stringify(apiEvent.detail.getPlayerResponse()));
|
||||
}
|
||||
}, { once: true, passive: true });
|
||||
};
|
||||
|
||||
@ -86,12 +86,19 @@ const registerCallback = (callback) => {
|
||||
|
||||
const registerProvider = (win) => {
|
||||
// This will be called when the song-info-front finds a new request with song data
|
||||
ipcMain.on("song-info-request", async (_, responseText) => {
|
||||
ipcMain.on("video-src-changed", async (_, responseText) => {
|
||||
await handleData(responseText, win);
|
||||
callbacks.forEach((c) => {
|
||||
c(songInfo);
|
||||
});
|
||||
});
|
||||
ipcMain.on("playPaused", (_, { isPaused, elapsedSeconds }) => {
|
||||
songInfo.isPaused = isPaused;
|
||||
songInfo.elapsedSeconds = elapsedSeconds;
|
||||
callbacks.forEach((c) => {
|
||||
c(songInfo);
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
const suffixesToRemove = [
|
||||
|
||||
Reference in New Issue
Block a user