Skip to content

Commit

Permalink
fix song-info-request
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Nov 22, 2021
1 parent 185ebbf commit 92452f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
18 changes: 13 additions & 5 deletions providers/song-info-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
9 changes: 8 additions & 1 deletion providers/song-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 92452f8

Please sign in to comment.