This commit is contained in:
botsy 2026-07-15 15:06:30 +03:00 committed by GitHub
commit b950ee8b8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -96,7 +96,7 @@ const Player = () => {
const [subtitlesMenuOpen, , closeSubtitlesMenu, toggleSubtitlesMenu] = useBinaryState(false);
const [audioMenuOpen, , closeAudioMenu, toggleAudioMenu] = useBinaryState(false);
const [speedMenuOpen, , closeSpeedMenu, toggleSpeedMenu] = useBinaryState(false);
const [statisticsMenuOpen, , closeStatisticsMenu, toggleStatisticsMenu] = useBinaryState(false);
const [statisticsMenuOpen, openStatisticsMenu, closeStatisticsMenu, toggleStatisticsMenu] = useBinaryState(false);
const [nextVideoPopupOpen, openNextVideoPopup, closeNextVideoPopup] = useBinaryState(false);
const [sideDrawerOpen, , closeSideDrawer, toggleSideDrawer] = useBinaryState(false);
@ -145,6 +145,7 @@ const Player = () => {
const playbackSpeed = React.useRef(video.state.playbackSpeed || 1);
const pressTimer = React.useRef(null);
const longPress = React.useRef(false);
const activeHoldCode = React.useRef(null);
const controlBarRef = React.useRef(null);
const HOLD_DELAY = 400;
@ -643,14 +644,6 @@ const Player = () => {
}
}, [video.state.playbackSpeed, onPlaybackSpeedChanged], !menusOpen);
onShortcut('statisticsMenu', () => {
closeMenus();
const stream = player.selected?.stream;
if (streamingServer?.statistics?.type !== 'Err' && typeof stream?.infoHash === 'string' && typeof stream?.fileIdx === 'number') {
toggleStatisticsMenu();
}
}, [player.selected, streamingServer.statistics, toggleStatisticsMenu]);
onShortcut('playNext', () => {
closeMenus();
if (player.nextVideo !== null) {
@ -672,20 +665,44 @@ const Player = () => {
longPress.current = false;
}
const isStatisticsEligible = () => {
const stream = player.selected?.stream;
return streamingServer?.statistics?.type !== 'Err'
&& typeof stream?.infoHash === 'string'
&& typeof stream?.fileIdx === 'number';
};
const onKeyDown = (e) => {
if (e.code !== 'Space' || e.repeat) return;
if (menusOpen || e.ctrlKey || e.metaKey || e.altKey) return;
if (e.repeat || e.ctrlKey || e.metaKey || e.altKey) return;
longPress.current = false;
if (e.code === 'Space') {
if (menusOpen) return;
pressTimer.current = setTimeout(() => {
longPress.current = true;
onPlaybackSpeedChanged(2, true);
}, HOLD_DELAY);
clearTimeout(pressTimer.current);
longPress.current = false;
activeHoldCode.current = 'Space';
pressTimer.current = setTimeout(() => {
longPress.current = true;
onPlaybackSpeedChanged(2, true);
}, HOLD_DELAY);
} else if (e.code === 'KeyD') {
clearTimeout(pressTimer.current);
longPress.current = false;
activeHoldCode.current = 'KeyD';
pressTimer.current = setTimeout(() => {
longPress.current = true;
if (isStatisticsEligible()) {
closeMenus();
openStatisticsMenu();
}
}, HOLD_DELAY);
}
};
const onKeyUp = (e) => {
if (e.code !== 'Space' && e.code !== 'ArrowRight' && e.code !== 'ArrowLeft') return;
if (e.code !== 'Space' && e.code !== 'ArrowRight' && e.code !== 'ArrowLeft' && e.code !== 'KeyD') return;
if (e.ctrlKey || e.metaKey || e.altKey) return;
if (e.code === 'ArrowRight' || e.code === 'ArrowLeft') {
@ -706,6 +723,19 @@ const Player = () => {
}
}
longPress.current = false;
activeHoldCode.current = null;
}
if (e.code === 'KeyD') {
clearTimeout(pressTimer.current);
pressTimer.current = null;
if (longPress.current) {
closeStatisticsMenu();
} else if (isStatisticsEligible()) {
closeMenus();
toggleStatisticsMenu();
}
longPress.current = false;
activeHoldCode.current = null;
}
};
@ -748,9 +778,14 @@ const Player = () => {
clearTimeout(pressTimer.current);
pressTimer.current = null;
if (longPress.current) {
onPlaybackSpeedChanged(playbackSpeed.current);
if (activeHoldCode.current === 'KeyD') {
closeStatisticsMenu();
} else {
onPlaybackSpeedChanged(playbackSpeed.current);
}
longPress.current = false;
}
activeHoldCode.current = null;
setSeeking(false);
};
@ -770,7 +805,7 @@ const Player = () => {
window.removeEventListener('mouseup', onMouseUp);
window.removeEventListener('blur', onBlur);
};
}, [routeFocused, menusOpen, video.state.volume, video.state.paused]);
}, [routeFocused, menusOpen, video.state.volume, video.state.paused, player.selected, streamingServer.statistics, openStatisticsMenu, closeStatisticsMenu, toggleStatisticsMenu, closeMenus]);
React.useEffect(() => {
video.events.on('error', onError);