mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
@ -19,7 +19,7 @@ function setupMPRIS() {
|
|||||||
|
|
||||||
function registerMPRIS(win) {
|
function registerMPRIS(win) {
|
||||||
const songControls = getSongControls(win);
|
const songControls = getSongControls(win);
|
||||||
const { playPause, next, previous } = songControls;
|
const { playPause, next, previous, volumeMinus10, volumePlus10 } = songControls;
|
||||||
try {
|
try {
|
||||||
const secToMicro = n => Math.round(Number(n) * 1e6);
|
const secToMicro = n => Math.round(Number(n) * 1e6);
|
||||||
const microToSec = n => Math.round(Number(n) / 1e6);
|
const microToSec = n => Math.round(Number(n) / 1e6);
|
||||||
@ -93,6 +93,22 @@ function registerMPRIS(win) {
|
|||||||
player.on('seek', seekBy);
|
player.on('seek', seekBy);
|
||||||
player.on('position', seekTo);
|
player.on('position', seekTo);
|
||||||
|
|
||||||
|
ipcMain.on('volumeChanged', (_, value) => {
|
||||||
|
player.volume = value;
|
||||||
|
});
|
||||||
|
player.on('volume', (newVolume) => {
|
||||||
|
// With keyboard shortcuts we can only change the volume in increments of 10, so round it.
|
||||||
|
const deltaVolume = Math.round((newVolume - player.volume) / 10);
|
||||||
|
|
||||||
|
if (deltaVolume > 0) {
|
||||||
|
for (let i = 0; i < deltaVolume; i++)
|
||||||
|
volumePlus10();
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < -deltaVolume; i++)
|
||||||
|
volumeMinus10();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
registerCallback(songInfo => {
|
registerCallback(songInfo => {
|
||||||
if (player) {
|
if (player) {
|
||||||
const data = {
|
const data = {
|
||||||
|
|||||||
@ -23,6 +23,7 @@ module.exports = () => {
|
|||||||
(is.linux() && config.plugins.isEnabled('shortcuts'))) {
|
(is.linux() && config.plugins.isEnabled('shortcuts'))) {
|
||||||
setupTimeChangeListener();
|
setupTimeChangeListener();
|
||||||
setupRepeatChangeListener();
|
setupRepeatChangeListener();
|
||||||
|
setupVolumeChangeListener();
|
||||||
}
|
}
|
||||||
const video = $('video');
|
const video = $('video');
|
||||||
// name = "dataloaded" and abit later "dataupdated"
|
// name = "dataloaded" and abit later "dataupdated"
|
||||||
@ -74,3 +75,13 @@ function setupRepeatChangeListener() {
|
|||||||
// 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', $('#right-controls .repeat').title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupVolumeChangeListener() {
|
||||||
|
const volumeObserver = new MutationObserver(mutations => {
|
||||||
|
ipcRenderer.send('volumeChanged', mutations[0].target.value);
|
||||||
|
});
|
||||||
|
volumeObserver.observe($('#right-controls .volume-slider'), { attributeFilter: ["value"] });
|
||||||
|
|
||||||
|
// Emit the initial value as well; as it's persistent between launches.
|
||||||
|
ipcRenderer.send('volumeChanged', $('#right-controls .volume-slider').value);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user