fix: don't create play pause method unneccessarily

This commit is contained in:
Manish
2021-10-14 10:16:36 +05:30
parent a76f12c01c
commit 81fb5118aa
2 changed files with 17 additions and 32 deletions

View File

@ -21,7 +21,7 @@ function _registerLocalShortcut(win, shortcut, action) {
function registerShortcuts(win, options) {
const songControls = getSongControls(win);
const { play, pause, playPause, next, previous, search } = songControls;
const { playPause, next, previous, search } = songControls;
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
@ -29,12 +29,14 @@ function registerShortcuts(win, options) {
_registerLocalShortcut(win, "CommandOrControl+F", search);
_registerLocalShortcut(win, "CommandOrControl+L", search);
registerCallback(songInfo => {
player.metadata = {
'mpris:length': songInfo.songDuration * 60 * 1000 * 1000, // In microseconds
'mpris:artUrl': songInfo.imageSrc,
'xesam:title': songInfo.title,
'xesam:artist': songInfo.artist
};
if (player) {
player.metadata = {
'mpris:length': songInfo.songDuration * 60 * 1000 * 1000, // In microseconds
'mpris:artUrl': songInfo.imageSrc,
'xesam:title': songInfo.title,
'xesam:artist': songInfo.artist
};
}
}
)
@ -46,16 +48,17 @@ function registerShortcuts(win, options) {
win.setSkipTaskbar(false);
win.show();
});
MPRISPlayer.on("playPause", () => {
console.log("Playpause");
})
MPRISPlayer.on("play", () => {
player.playbackStatus = 'Playing';
play()
if (MPRISPlayer.playbackStatus !== 'Playing') {
MPRISPlayer.playbackStatus = 'Playing';
playPause()
}
});
MPRISPlayer.on("pause", () => {
player.playbackStatus = 'Paused';
pause()
if (MPRISPlayer.playbackStatus === 'Playing') {
MPRISPlayer.playbackStatus = 'Paused';
playPause()
}
});
MPRISPlayer.on("next", () => {
next()

View File

@ -15,22 +15,4 @@ module.exports = () => {
videoStream.pause();
}
});
ipcRenderer.on("play", () => {
if (!videoStream) {
videoStream = document.querySelector(".video-stream");
}
if (videoStream.paused) videoStream.play();
});
ipcRenderer.on("pause", () => {
if (!videoStream) {
videoStream = document.querySelector(".video-stream");
}
videoStream.yns_pause ?
videoStream.yns_pause() :
videoStream.pause();
});
};