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

View File

@ -15,22 +15,4 @@ module.exports = () => {
videoStream.pause(); 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();
});
}; };