removed unnecessary if and used better Repeat change detection

This commit is contained in:
David Metzler
2023-01-28 20:36:31 +01:00
parent 317e3af412
commit 8bf2c8397e
2 changed files with 5 additions and 42 deletions

View File

@ -89,10 +89,9 @@ function registerMPRIS(win) {
}); });
ipcMain.on('volumeChanged', (_, value) => { ipcMain.on('volumeChanged', (_, value) => {
if (config.plugins.isEnabled('precise-volume')) { player.volume = value / 100;
player.volume = value / 100;
}
}); });
player.on('volume', (newVolume) => { player.on('volume', (newVolume) => {
if (config.plugins.isEnabled('precise-volume')) { if (config.plugins.isEnabled('precise-volume')) {
// With precise volume we can set the volume to the exact value. // With precise volume we can set the volume to the exact value.

View File

@ -67,50 +67,14 @@ function setupTimeChangeListener() {
} }
function setupRepeatChangeListener() { function setupRepeatChangeListener() {
const mp = { NONE: "Repeat off", ONE: "Repeat one", ALL: "Repeat all" }
const repeatObserver = new MutationObserver(mutations => { const repeatObserver = new MutationObserver(mutations => {
document.cookie.split(';').forEach((cookie) => { ipcRenderer.send('repeatChanged', mp[mutations[0].target.__dataHost.getState().queue.repeatMode])
let cookieName = cookie.substring(0, cookie.indexOf("=")).replaceAll(" ", "");
if (cookieName === 'PREF') {
let value = cookie.replace(cookieName + "=", "").replaceAll(" ", "");
value.split('&').forEach((pair) => {
if (pair !== '') {
let splitpair = pair.split('=');
if (splitpair[0] === "repeat") {
if (splitpair[1] === "NONE")
ipcRenderer.send('repeatChanged', "Repeat off");
else if (splitpair[1] === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
ipcRenderer.send('repeatChanged', "Repeat one");
else if (splitpair[1] === "ALL")
ipcRenderer.send('repeatChanged', "Repeat all");
}
}
});
}
});
}); });
repeatObserver.observe($('#right-controls .repeat'), {attributeFilter: ["title"]}); repeatObserver.observe($('#right-controls .repeat'), {attributeFilter: ["title"]});
// Emit the initial value as well; as it's persistent between launches. // Emit the initial value as well; as it's persistent between launches.
// ipcRenderer.send('repeatChanged', $('#right-controls .repeat').title); ipcRenderer.send('repeatChanged', mp[$('ytmusic-player-bar').getState().queue.repeatMode]);
document.cookie.split(';').forEach((cookie) => {
let cookieName = cookie.substring(0, cookie.indexOf("=")).replaceAll(" ", "");
if (cookieName === 'PREF') {
let value = cookie.replace(cookieName + "=", "").replaceAll(" ", "");
value.split('&').forEach((pair) => {
if (pair !== '') {
let splitpair = pair.split('=');
if (splitpair[0] === "repeat") {
if (splitpair[1] === "NONE")
ipcRenderer.send('repeatChanged', "Repeat off");
else if (splitpair[1] === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
ipcRenderer.send('repeatChanged', "Repeat one");
else if (splitpair[1] === "ALL")
ipcRenderer.send('repeatChanged', "Repeat all");
}
}
});
}
});
} }
function setupVolumeChangeListener(api) { function setupVolumeChangeListener(api) {