Skip to content

Commit

Permalink
Merge pull request #259 from Araxeus/force-pause
Browse files Browse the repository at this point in the history
fix playPause bugs by directly playPause video element
  • Loading branch information
th-ch authored May 7, 2021
2 parents c76d8c7 + e00be8f commit 250940d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
8 changes: 6 additions & 2 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { remote } = require("electron");
const config = require("./config");
const { fileExists } = require("./plugins/utils");
const setupFrontLogger = require("./providers/front-logger");
const setupSongControl = require("./providers/song-controls-front");
const setupSongInfo = require("./providers/song-info-front");

const plugins = config.plugins.getEnabled();

Expand Down Expand Up @@ -37,8 +39,10 @@ document.addEventListener("DOMContentLoaded", () => {
});

// inject song-info provider
const songInfoProviderPath = path.join(__dirname, "providers", "song-info-front.js")
fileExists(songInfoProviderPath, require(songInfoProviderPath));
setupSongInfo();

// inject song-control provider
setupSongControl();

// inject front logger
setupFrontLogger();
Expand Down
18 changes: 18 additions & 0 deletions providers/song-controls-front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { ipcRenderer } = require("electron");

let videoStream = document.querySelector(".video-stream");
module.exports = () => {
ipcRenderer.on("playPause", () => {
if (!videoStream) {
videoStream = document.querySelector(".video-stream");
}

if (videoStream.paused) {
videoStream.play();
} else {
videoStream.yns_pause ?
videoStream.yns_pause() :
videoStream.pause();
}
});
};
2 changes: 1 addition & 1 deletion providers/song-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = (win) => {
// Playback
previous: () => pressKey(win, "k"),
next: () => pressKey(win, "j"),
playPause: () => pressKey(win, "space"),
playPause: () => win.webContents.send("playPause"),
like: () => pressKey(win, "_"),
dislike: () => pressKey(win, "+"),
go10sBack: () => pressKey(win, "h"),
Expand Down
9 changes: 4 additions & 5 deletions providers/song-info-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
});

const injectListener = () => {
var oldXHR = window.XMLHttpRequest;
const oldXHR = window.XMLHttpRequest;
function newXHR() {
var realXHR = new oldXHR();
const realXHR = new oldXHR();
realXHR.addEventListener(
"readystatechange",
() => {
if (realXHR.readyState == 4 && realXHR.status == 200) {
if (realXHR.responseURL.includes("/player")) {
if (realXHR.readyState === 4 && realXHR.status === 200
&& realXHR.responseURL.includes("/player")) {
// if the request contains the song info, send the response to ipcMain
ipcRenderer.send("song-info-request", realXHR.responseText);
}
}
},
false
Expand Down

0 comments on commit 250940d

Please sign in to comment.