mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Support MPRIS loop
This commit is contained in:
@ -34,6 +34,35 @@ function registerMPRIS(win) {
|
||||
let currentSeconds = 0;
|
||||
ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
|
||||
|
||||
let currentLoopStatus = undefined;
|
||||
let manuallySwitchingStatus = false;
|
||||
ipcMain.on("repeatChanged", (_, mode) => {
|
||||
if (manuallySwitchingStatus)
|
||||
return;
|
||||
|
||||
if (mode == "Repeat off")
|
||||
currentLoopStatus = "None";
|
||||
else if (mode == "Repeat one")
|
||||
currentLoopStatus = "Track";
|
||||
else if (mode == "Repeat all")
|
||||
currentLoopStatus = "Playlist";
|
||||
|
||||
player.loopStatus = currentLoopStatus;
|
||||
});
|
||||
player.on("loopStatus", (status) => {
|
||||
// switchRepeat cycles between states in that order
|
||||
const switches = ["None", "Playlist", "Track"];
|
||||
const curIdx = switches.indexOf(currentLoopStatus);
|
||||
const newIdx = switches.indexOf(status);
|
||||
|
||||
// Get a delta in the range [0,2]
|
||||
const delta = ((newIdx - curIdx) % 3 + 3) % 3;
|
||||
|
||||
manuallySwitchingStatus = true;
|
||||
songControls.switchRepeat(delta);
|
||||
manuallySwitchingStatus = false;
|
||||
})
|
||||
|
||||
player.getPosition = () => secToMicro(currentSeconds)
|
||||
|
||||
player.on("raise", () => {
|
||||
|
||||
@ -20,7 +20,10 @@ module.exports = (win) => {
|
||||
go1sBack: () => pressKey(win, "h", ["shift"]),
|
||||
go1sForward: () => pressKey(win, "l", ["shift"]),
|
||||
shuffle: () => pressKey(win, "s"),
|
||||
switchRepeat: () => pressKey(win, "r"),
|
||||
switchRepeat: (n = 1) => {
|
||||
for (let i = 0; i != n; ++i)
|
||||
pressKey(win, "r");
|
||||
},
|
||||
// General
|
||||
volumeMinus10: () => pressKey(win, "-"),
|
||||
volumePlus10: () => pressKey(win, "="),
|
||||
|
||||
@ -22,6 +22,7 @@ module.exports = () => {
|
||||
if (config.plugins.isEnabled('tuna-obs') ||
|
||||
(is.linux() && config.plugins.isEnabled('shortcuts'))) {
|
||||
setupTimeChangeListener();
|
||||
setupRepeatChangeListener();
|
||||
}
|
||||
const video = $('video');
|
||||
// name = "dataloaded" and abit later "dataupdated"
|
||||
@ -63,3 +64,13 @@ function setupTimeChangeListener() {
|
||||
});
|
||||
progressObserver.observe($('#progress-bar'), { attributeFilter: ["value"] })
|
||||
}
|
||||
|
||||
function setupRepeatChangeListener() {
|
||||
const repeatObserver = new MutationObserver(mutations => {
|
||||
ipcRenderer.send('repeatChanged', mutations[0].target.title);
|
||||
});
|
||||
repeatObserver.observe($('#right-controls .repeat'), { attributeFilter: ["title"] });
|
||||
|
||||
// Emit the initial value as well; as it's persistent between launches.
|
||||
ipcRenderer.send('repeatChanged', $('#right-controls .repeat').title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user