* Remove 1920px max width * Fix position of list controls menu * Match size and color of search input * Adjust library header sizing * Move app menu to sidebar * Increase row buffer on play queue list * Fix query builder styles * Fix playerbar slider track bg * Adjust titlebar styles * Fix invalid modal prop * Various adjustments to detail pages * Fix sidebar height calculation * Fix list null indicators, add filter indicator * Adjust playqueue styles * Fix jellyfin releaseYear normalization * Suppress browser context menu on ag-grid * Add radius to drawer queue -- normalize layout * Add modal styles to provider theme * Fix playlist song list pagination * Add disc number to albums with more than one disc * Fix query builder boolean values * Adjust input placeholder color * Properly handle rating/favorite from context menu on table * Conform dropdown menu styles to context menu * Increase sort type select width * Fix drawer queue radius * Change primary color * Prevent volume wheel from invalid values * Add icons to query builder dropdowns * Update notification styles * Update scrollbar thumb styles * Remove "add to playlist" on smart playlists * Fix "add to playlist" from context menu
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { useEffect, WheelEvent } from 'react';
|
|
import isElectron from 'is-electron';
|
|
import { useMuted, usePlayerControls, useVolume } from '/@/renderer/store';
|
|
import { useGeneralSettings } from '/@/renderer/store/settings.store';
|
|
|
|
const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null;
|
|
|
|
export const useRightControls = () => {
|
|
const { setVolume, setMuted } = usePlayerControls();
|
|
const volume = useVolume();
|
|
const muted = useMuted();
|
|
const { volumeWheelStep } = useGeneralSettings();
|
|
|
|
// Ensure that the mpv player volume is set on startup
|
|
useEffect(() => {
|
|
if (isElectron()) {
|
|
mpvPlayer.volume(volume);
|
|
|
|
if (muted) {
|
|
mpvPlayer.mute();
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
const handleVolumeSlider = (e: number) => {
|
|
mpvPlayer.volume(e);
|
|
setVolume(e);
|
|
};
|
|
|
|
const handleVolumeSliderState = (e: number) => {
|
|
setVolume(e);
|
|
};
|
|
|
|
const handleVolumeWheel = (e: WheelEvent<HTMLDivElement>) => {
|
|
let volumeToSet;
|
|
if (e.deltaY > 0) {
|
|
const newVolumeLessThanZero = volume - volumeWheelStep < 0;
|
|
if (newVolumeLessThanZero) {
|
|
volumeToSet = 0;
|
|
} else {
|
|
volumeToSet = volume - volumeWheelStep;
|
|
}
|
|
} else {
|
|
const newVolumeGreaterThanHundred = volume + volumeWheelStep > 100;
|
|
if (newVolumeGreaterThanHundred) {
|
|
volumeToSet = 100;
|
|
} else {
|
|
volumeToSet = volume + volumeWheelStep;
|
|
}
|
|
}
|
|
|
|
mpvPlayer.volume(volumeToSet);
|
|
setVolume(volumeToSet);
|
|
};
|
|
|
|
const handleMute = () => {
|
|
setMuted(!muted);
|
|
mpvPlayer.mute();
|
|
};
|
|
|
|
return {
|
|
handleMute,
|
|
handleVolumeSlider,
|
|
handleVolumeSliderState,
|
|
handleVolumeWheel,
|
|
};
|
|
};
|