diff --git a/package.json b/package.json index b9b7160..3dc6a59 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "huangguo-client", "private": true, - "version": "1.1.0", + "version": "1.2.0", "license": "PolyForm-Noncommercial-1.0.0", "type": "module", "scripts": { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 3103cdc..0feef11 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1605,7 +1605,7 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "huangguo-client" -version = "1.1.0" +version = "1.2.0" dependencies = [ "aes", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b012090..d1184c6 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "huangguo-client" -version = "1.1.0" +version = "1.2.0" description = "HGhub · 黄果短剧客户端" authors = ["HGhub"] license = "PolyForm-Noncommercial-1.0.0" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ef97067..90e62ad 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "HGhub", - "version": "1.1.0", + "version": "1.2.0", "identifier": "com.hghub.huangguo", "build": { "beforeDevCommand": "pnpm dev", diff --git a/src/components/Feed.tsx b/src/components/Feed.tsx index 21d5176..4dad411 100644 --- a/src/components/Feed.tsx +++ b/src/components/Feed.tsx @@ -5,11 +5,12 @@ import { useStore } from "../store"; import { Avatar, Img, Sheet } from "./ui"; import VideoSurface, { type VideoHandle } from "./VideoSurface"; import PlayerControls from "./PlayerControls"; +import PlaybackLock from "./PlaybackLock"; import { ArticlePanel, CommentsPanel, EpisodesPanel } from "./Panels"; import { setBackHandler } from "../back"; import { IBack, IBoltF, IChevR, IChevronDown, IChevronUp, IClose, ICommentF, ICompress, IExpand, IFileText, IHeart, IHeartF, - ILink, IList, ILockF, IPauseF, IPlayF, IStar, IStarF, IVol, IVolMute, + ILink, IList, ILockF, IPauseF, IPlayF, ISearch, IStar, IStarF, IVol, IVolMute, } from "../icons"; type Props = { @@ -50,6 +51,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind const [vsize, setVsize] = useState({ w: 0, h: 0 }); const [buffered, setBuffered] = useState(0); const [paused, setPaused] = useState(false); + const [controlsLocked, setControlsLocked] = useState(false); const [rate, setRate] = useState(1); const [waiting, setWaiting] = useState(false); const [err, setErr] = useState(""); @@ -99,7 +101,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind const [barPct, setBarPct] = useState(null); const gesture = useRef<{ x: number; y: number; startY: number; t: number; timer: number | null; - mode: "idle" | "hold" | "scrub"; base: number; width: number; + mode: "idle" | "hold" | "scrub" | "pan"; base: number; width: number; playing: boolean; } | null>(null); const curId = videoIds[index]; @@ -270,7 +272,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind /* 键盘 */ useEffect(() => { - if (!active) return; + if (!active || controlsLocked) return; const fn = (e: KeyboardEvent) => { const t = e.target as HTMLElement; if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA")) return; @@ -294,7 +296,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind window.addEventListener("keydown", fn); return () => window.removeEventListener("keydown", fn); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [active, panel, time, index]); + }, [active, controlsLocked, panel, time, index]); /* 安卓返回键:面板打开时先关面板 */ useEffect(() => { @@ -318,13 +320,14 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind /* —— 长按 2x(上滑锁定) / 横拖定位 / 单击暂停 —— */ const onDown = (e: React.PointerEvent) => { - if (isDesktop) return; + if (isDesktop || controlsLocked || !active || gesture.current || e.button !== 0) return; const el = e.currentTarget; const width = el.clientWidth || 1; try { el.setPointerCapture(e.pointerId); } catch { /* ignore */ } const g = { x: e.clientX, y: e.clientY, startY: e.clientY, t: Date.now(), base: time, width, - mode: "idle" as "idle" | "hold" | "scrub", + mode: "idle" as "idle" | "hold" | "scrub" | "pan", + playing: videoRef.current?.el()?.paused === false, timer: window.setTimeout(() => { const cur = gesture.current; if (!cur || cur.mode !== "idle") return; @@ -362,6 +365,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind videoRef.current?.pause(); } else if (Math.abs(dy) > 14) { if (g.timer) window.clearTimeout(g.timer); + g.mode = "pan"; } return; } @@ -375,7 +379,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind } }; - const onUp = () => { + const onUp = (cancelled = false) => { const g = gesture.current; gesture.current = null; if (!g) return; @@ -384,7 +388,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind if (g.mode === "hold") { holdRef.current = false; setHoldSpeed(false); - if (lockArmedRef.current) { + if (!cancelled && lockArmedRef.current) { setSpeedLock(true); toast("已锁定 2.0x 倍速 · 点顶部标签解除", "info"); } @@ -394,15 +398,28 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind } if (g.mode === "scrub") { const target = scrubTarget.current; - if (target != null) videoRef.current?.seek(target, "mobile_gesture"); + if (!cancelled && target != null) videoRef.current?.seek(target, "mobile_gesture"); setScrub(null); scrubTarget.current = null; - if (!paused) videoRef.current?.play(); + if (g.playing && active) videoRef.current?.play(); return; } - if (Date.now() - g.t < 260) videoRef.current?.toggle(); + if (!cancelled && g.mode === "idle" && Date.now() - g.t < 260) videoRef.current?.toggle(); }; + useEffect(() => { + if (!active || controlsLocked) onUp(true); + // Cancel pending gestures when the page is hidden or controls are locked. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [active, controlsLocked]); + + useEffect(() => () => { + if (gesture.current?.timer) window.clearTimeout(gesture.current.timer); + gesture.current = null; + }, [playKey]); + + const lockControls = () => { setPanel(null); setControlsLocked(true); }; + /* 长按倍速期间禁止原生滚动,否则上滑会被列表吃掉、锁不住倍速 */ useEffect(() => { if (isDesktop) return undefined; @@ -506,8 +523,9 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind return (
{ if (isDesktop) wake(); }}> +
{/* 氛围背景 */}
{posterUrl && } @@ -522,7 +540,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
{isActive && playUrl ? (
+ onPointerDown={onDown} onPointerMove={onMove} onPointerUp={() => onUp()} onPointerCancel={() => onUp(true)} onLostPointerCapture={() => onUp(true)}> {index + 1} / {videoIds.length}
) : ( -
+
{title} {index + 1} / {videoIds.length} -
) ) : null} @@ -748,7 +763,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind paused={paused} time={time} duration={duration} buffered={buffered} rate={rate} muted={muted} volume={volume} theater={theater} fullscreen={fullscreen} visible={active && !idle} - seekEnabled={active} + seekEnabled={active && !controlsLocked} seekKey={playKey} nextDisabled={!episodes.some((e) => e.ep_num === curEp + 1) && index >= videoIds.length - 1} nextTitle={episodes.some((e) => e.ep_num === curEp + 1) ? "下一集 E" : "下一部 ↓"} @@ -759,6 +774,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind onMute={() => setMuted((m) => !m)} onVolume={(v) => setVolume(v)} onPip={togglePip} + onLock={lockControls} onTheater={() => setTheater((v) => !v)} onFullscreen={toggleFull} onNext={() => { @@ -928,6 +944,20 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind )} +
+ {!isDesktop && !controlsLocked && active && ( +
+ {!fs && } + + {!fs && } +
+ )} + {controlsLocked && { setControlsLocked(false); wake(); }} />}
); } diff --git a/src/components/PlaybackLock.tsx b/src/components/PlaybackLock.tsx new file mode 100644 index 0000000..8f6101a --- /dev/null +++ b/src/components/PlaybackLock.tsx @@ -0,0 +1,28 @@ +import { useEffect } from "react"; +import { ILockF } from "../icons"; + +/** Shield pointer input and playback shortcuts without pausing the media. */ +export default function PlaybackLock({ active, onUnlock }: { active: boolean; onUnlock: () => void }) { + useEffect(() => { + if (!active) return; + const block = (e: KeyboardEvent) => { + const target = e.target as HTMLElement | null; + if (target?.closest("input, textarea, [contenteditable='true'], [data-playback-unlock]")) return; + const key = e.key.length === 1 ? e.key.toLowerCase() : e.key; + if ([" ", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "PageUp", "PageDown", "f", "t", "m", "l", "s", "c", "e"].includes(key)) { + e.preventDefault(); + e.stopImmediatePropagation(); + } + }; + window.addEventListener("keydown", block, true); + return () => window.removeEventListener("keydown", block, true); + }, [active]); + + return
e.stopPropagation()} onClick={e => e.stopPropagation()} onWheel={e => e.stopPropagation()}> + +
; +} diff --git a/src/components/Player.tsx b/src/components/Player.tsx index 132c59a..df86e6a 100644 --- a/src/components/Player.tsx +++ b/src/components/Player.tsx @@ -4,7 +4,8 @@ import { fmtTime, playlist } from "../api"; import { mediaResource, observeHls, usePlayerDiagnostics } from "../playbackDiagnostics"; import { usePlaybackActivity } from "../usePlaybackActivity"; import { useSeekInput } from "../useSeekInput"; -import { ICompress, IExpand, IPauseF, IPlayF, IVol, IVolMute } from "../icons"; +import PlaybackLock from "./PlaybackLock"; +import { ICompress, IExpand, ILockF, IPauseF, IPlayF, IVol, IVolMute } from "../icons"; type Props = { src: string; // 原始 m3u8 地址 @@ -38,7 +39,8 @@ export default function Player({ const [full, setFull] = useState(false); const [rate, setRate] = useState(1); const [errMsg, setErrMsg] = useState(""); - const seek = useSeekInput({ time, duration, enabled: active, resetKey: src, + const [controlsLocked, setControlsLocked] = useState(false); + const seek = useSeekInput({ time, duration, enabled: active && !controlsLocked, resetKey: src, onInteraction: (phase, input, target, pointerTarget) => trace(`seek.input.${phase}`, { input, target, pointer_target: pointerTarget }), onSeek: (target, input) => { const video = videoRef.current; @@ -144,6 +146,7 @@ export default function Player({ return (
+
)} +
+ {controlsLocked && setControlsLocked(false)} />}
); } diff --git a/src/components/PlayerControls.tsx b/src/components/PlayerControls.tsx index 6cbfa3e..3eb025a 100644 --- a/src/components/PlayerControls.tsx +++ b/src/components/PlayerControls.tsx @@ -1,7 +1,7 @@ import { useEffect, useRef, useState } from "react"; import { fmtTime } from "../api"; import { useSeekInput } from "../useSeekInput"; -import { ICheck, ICompress, IExpand, INext, IPauseF, IPip, IPlayF, ITheater, IVol, IVolMute } from "../icons"; +import { ICheck, ICompress, IExpand, ILockF, INext, IPauseF, IPip, IPlayF, ITheater, IVol, IVolMute } from "../icons"; type Props = { paused: boolean; @@ -25,6 +25,7 @@ type Props = { onMute: () => void; onVolume: (v: number) => void; onPip: () => void; + onLock: () => void; onTheater?: () => void; onFullscreen: () => void; onNext?: () => void; @@ -34,7 +35,7 @@ const clock = (s: number) => fmtTime(Math.max(0, s || 0)).padStart(5, "0"); export default function PlayerControls({ paused, time, duration, buffered = 0, rate, muted, volume, theater = false, fullscreen = false, - visible = true, seekEnabled = true, seekKey, nextDisabled = false, nextTitle = "下一个", onToggle, onSeek, onSeekInteraction, onRate, onMute, onVolume, onPip, onTheater, onFullscreen, onNext, + visible = true, seekEnabled = true, seekKey, nextDisabled = false, nextTitle = "下一个", onToggle, onSeek, onSeekInteraction, onRate, onMute, onVolume, onPip, onLock, onTheater, onFullscreen, onNext, }: Props) { const [speedOpen, setSpeedOpen] = useState(false); const boxRef = useRef(null); @@ -98,6 +99,7 @@ export default function PlayerControls({
+ {!fullscreen && onTheater && ( diff --git a/src/index.css b/src/index.css index a442aed..fbc63bc 100644 --- a/src/index.css +++ b/src/index.css @@ -352,6 +352,12 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w transition: opacity .25s; } .desktop-controls.is-hidden { opacity: 0; pointer-events: none; } +.playback-unlock { color: rgba(255,255,255,.38); background: rgba(0,0,0,.12); transition: color .2s, background .2s; } +.playback-unlock:hover, .playback-unlock:focus-visible { color: rgba(255,255,255,.9); background: rgba(0,0,0,.4); } +.player-root.is-locked [inert] button, +.player-root.is-locked .desktop-controls, +.player-root.is-locked .desktop-video-meta, +.player-root.is-locked .desktop-social { visibility: hidden; } .desktop-control-row { display: flex; align-items: center; gap: 5px; height: 38px; } .player-control { height: 32px; min-width: 32px; padding: 0 8px; border-radius: 7px; diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 4b4ad1f..dda40f6 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -1,13 +1,13 @@ import { useCallback, useEffect, useRef, useState } from "react"; import Feed from "../components/Feed"; -import { api, isMobile } from "../api"; +import { api } from "../api"; import type { VideoCard } from "../types"; import { useStore } from "../store"; -import { ISearch, IVol, IVolMute } from "../icons"; +import { ISearch } from "../icons"; import { Empty } from "../components/ui"; export default function Home({ active, bottomInset }: { active: boolean; bottomInset: number }) { - const { muted, setMuted, setTab, toast, fs } = useStore(); + const { toast } = useStore(); const [items, setItems] = useState([]); const [page, setPage] = useState(1); const [loading, setLoading] = useState(false); @@ -57,22 +57,6 @@ export default function Home({ active, bottomInset }: { active: boolean; bottomI ) : (
)} - - {/* 移动端:静音 + 搜索(压在视频上,固定白字 + 半透明黑底) */} - {isMobile && !fs && ( -
-
- - -
-
- )}
); }