mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
Fixed recursive volume changes that caused cpu spike, Switched Repeat Modes to NONE|ONE|ALL
This commit is contained in:
@ -36,11 +36,11 @@ function registerMPRIS(win) {
|
||||
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
|
||||
|
||||
ipcMain.on("repeatChanged", (_, mode) => {
|
||||
if (mode === "Repeat off")
|
||||
if (mode === "NONE")
|
||||
player.loopStatus = mpris.LOOP_STATUS_NONE;
|
||||
else if (mode === "Repeat one") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
|
||||
else if (mode === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
|
||||
player.loopStatus = mpris.LOOP_STATUS_PLAYLIST;
|
||||
else if (mode === "Repeat all")
|
||||
else if (mode === "ALL")
|
||||
player.loopStatus = mpris.LOOP_STATUS_TRACK;
|
||||
});
|
||||
player.on("loopStatus", (status) => {
|
||||
@ -88,14 +88,33 @@ function registerMPRIS(win) {
|
||||
shuffle();
|
||||
});
|
||||
|
||||
ipcMain.on('volumeChanged', (_, value) => {
|
||||
player.volume = value / 100;
|
||||
let mprisVolNewer = false;
|
||||
let autoUpdate = false;
|
||||
ipcMain.on('volumeChanged', (_, newVol) => {
|
||||
if (parseInt(player.volume * 100) !== newVol) {
|
||||
if (mprisVolNewer) {
|
||||
mprisVolNewer = false;
|
||||
autoUpdate = false;
|
||||
} else {
|
||||
autoUpdate = true;
|
||||
player.volume = parseFloat((newVol / 100).toFixed(2));
|
||||
mprisVolNewer = false;
|
||||
autoUpdate = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
player.on('volume', (newVolume) => {
|
||||
if (config.plugins.isEnabled('precise-volume')) {
|
||||
// With precise volume we can set the volume to the exact value.
|
||||
win.webContents.send('setVolume', newVolume * 100)
|
||||
let newVol = parseInt(newVolume * 100);
|
||||
if (parseInt(player.volume * 100) !== newVol) {
|
||||
if (!autoUpdate){
|
||||
mprisVolNewer = true;
|
||||
autoUpdate = false;
|
||||
win.webContents.send('setVolume', newVol);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// With keyboard shortcuts we can only change the volume in increments of 10, so round it.
|
||||
let deltaVolume = Math.round((newVolume - player.volume) * 10);
|
||||
|
||||
@ -67,14 +67,13 @@ function setupTimeChangeListener() {
|
||||
}
|
||||
|
||||
function setupRepeatChangeListener() {
|
||||
const mp = { NONE: "Repeat off", ONE: "Repeat one", ALL: "Repeat all" }
|
||||
const repeatObserver = new MutationObserver(mutations => {
|
||||
ipcRenderer.send('repeatChanged', mp[mutations[0].target.__dataHost.getState().queue.repeatMode])
|
||||
ipcRenderer.send('repeatChanged', mutations[0].target.__dataHost.getState().queue.repeatMode)
|
||||
});
|
||||
repeatObserver.observe($('#right-controls .repeat'), {attributeFilter: ["title"]});
|
||||
|
||||
// Emit the initial value as well; as it's persistent between launches.
|
||||
ipcRenderer.send('repeatChanged', mp[$('ytmusic-player-bar').getState().queue.repeatMode]);
|
||||
ipcRenderer.send('repeatChanged', $('ytmusic-player-bar').getState().queue.repeatMode);
|
||||
}
|
||||
|
||||
function setupVolumeChangeListener(api) {
|
||||
|
||||
Reference in New Issue
Block a user