feat(player): set right ctrl vol max to mpv's vol max if player==local (#2198)

This commit is contained in:
Simon Slamka
2026-07-16 08:43:43 +03:00
committed by GitHub
parent 5e79e385d9
commit ddd45ad5ba
9 changed files with 106 additions and 21 deletions
+5 -2
View File
@@ -11,6 +11,7 @@ import { createLog } from '../../../utils';
import { store } from '../settings';
import { isMacOS, isWindows } from '/@/main/env';
import { MPV_VOLUME_MAX_CEILING } from '/@/shared/constants/volume';
import { PlayerData } from '/@/shared/types/domain-types';
declare module 'node-mpv';
@@ -493,10 +494,12 @@ ipcMain.on('player-auto-next', async (_event, url?: string) => {
}
});
// Sets the volume to the given value (0-100)
// Sets the volume to the given value. mpv clamps to its effective --volume-max,
// so the upper bound here is just a sanity guard; mpv itself is the final
// authority on how loud it will actually go.
ipcMain.on('player-volume', async (_event, value: number) => {
try {
if (!value || value < 0 || value > 100) {
if (value == null || Number.isNaN(value) || value < 0 || value > MPV_VOLUME_MAX_CEILING) {
return;
}
+5 -7
View File
@@ -2,6 +2,7 @@ import { ipcMain } from 'electron';
import Player from 'mpris-service';
import { getMainWindow } from '/@/main/index';
import { MPV_VOLUME_MAX_CEILING } from '/@/shared/constants/volume';
import { QueueSong } from '/@/shared/types/domain-types';
import { PlayerRepeat, PlayerStatus } from '/@/shared/types/types';
@@ -69,14 +70,11 @@ mprisPlayer.on('previous', () => {
}
});
// The renderer clamps to the active backend's maximum (mpv's --volume-max when
// mpv is selected), since that range is derived from settings the renderer owns.
// Only a sanity range is enforced here.
mprisPlayer.on('volume', (vol: number) => {
let volume = Math.round(vol * 100);
if (volume > 100) {
volume = 100;
} else if (volume < 0) {
volume = 0;
}
const volume = Math.min(MPV_VOLUME_MAX_CEILING, Math.max(0, Math.round(vol * 100)));
getMainWindow()?.webContents.send('request-volume', {
volume,