address more coderabbit review

This commit is contained in:
Kevin B. committed 2026-11-24 19:28:22 -05:00
1 parent e8ee3eb732
commit e9134ccd2b
13 files changed
+82 -39

No files matched your search

+9 -8
View File
@@ -16,14 +16,14 @@
<p
v-for="(line, index) in lyrics"
:key="index"
:class="{ active: syncedLyrics && !line.untimed && line.timestamp === lyrics[activeLyricIndex]?.timestamp, 'no-seek': !syncedLyrics }"
:class="{ active: syncedLyrics && !line.untimed && line.timestamp === lyrics[activeLyricIndex]?.timestamp, 'no-seek': !isSeekable(line) }"
class="lyric-line"
@click.stop="syncedLyrics && seek(line.timestamp)"
@keydown.enter.stop.prevent="syncedLyrics && seek(line.timestamp)"
@keydown.space.stop.prevent="syncedLyrics && seek(line.timestamp)"
:role="syncedLyrics ? 'button' : undefined"
:tabindex="syncedLyrics ? 0 : undefined"
:aria-label="syncedLyrics ? `Seek to ${line.text}` : undefined"
@click.stop="isSeekable(line) && seek(line.timestamp)"
@keydown.enter.stop.prevent="isSeekable(line) && seek(line.timestamp)"
@keydown.space.stop.prevent="isSeekable(line) && seek(line.timestamp)"
:role="isSeekable(line) ? 'button' : undefined"
:tabindex="isSeekable(line) ? 0 : undefined"
:aria-label="isSeekable(line) ? `Seek to ${line.text}` : undefined"
>
<template v-if="index === activeLyricIndex && hasFullWordCoverage(line)">
<span
@@ -50,7 +50,7 @@ import type Plyr from "plyr";
import FloatingActionButton from "@/components/settings/FloatingActionButton.vue";
import { useI18n } from "@/i18n/index.ts";
import { isSyncedLyrics } from "@/utils/lyrics.ts";
import type { LyricLines } from "@/utils/lyrics.ts";
import type { LyricLine, LyricLines } from "@/utils/lyrics.ts";
const scrollLocked = defineModel<boolean>("scrollLocked");
@@ -76,6 +76,7 @@ const activeLyricIndex = ref(-1);
const activeWordIndex = ref(-1);
const syncedLyrics = computed(() => isSyncedLyrics(props.lyrics));
const isSeekable = (line: LyricLine) => syncedLyrics.value && !line.untimed;
// "Title - Artist" shown above the lyrics from the [ti:] [ar:] tags on lyrics (if present)
const meta = computed(() => [props.lyrics.lrcMeta?.title, props.lyrics.lrcMeta?.artist].filter(Boolean).join(" - "));
const lockLabel = computed(() => (scrollLocked.value ? t("player.unlockLyrics") : t("player.lockLyrics")));
@@ -244,7 +244,6 @@ const playbackQueueState = usePlaybackQueue({
});
const {
queueCount,
playbackQueue,
loop,
toastVisible,
toastType,
@@ -260,7 +259,7 @@ const {
resetPlaybackMenuState,
} = playbackQueueState;
const shouldAutoplay = computed(() => props.autoPlayEnabled || playbackQueue.value.length > 1);
const shouldAutoplay = computed(() => props.autoPlayEnabled);
let seekOnReleaseCleanup: (() => void) | null = null;
@@ -149,7 +149,7 @@ describe("AudioPlayer file swap", () => {
session = installMediaSession();
vi.stubGlobal(
"URL",
Object.assign(URL, {
Object.assign(class extends URL {}, {
createObjectURL: vi.fn(() => {
const url = `blob:art-${created.length}`;
created.push(url);
@@ -466,6 +466,8 @@ describe("VideoPlayer file swap", () => {
hoisted.offerGate = null;
await swapTo(FILE_B);
expect(fakePlayers).toHaveLength(1);
expect(video().getAttribute("src")).toBe("/raw/b.mp4");
release();
await settle();
+5 -12
View File
@@ -22,6 +22,7 @@
zIndex: 5 + prompts.indexOf(prompt),
}"
:aria-label="`${prompt.name}-prompt`"
:data-prompt-id="prompt.id"
tabindex="-1"
>
<header
@@ -622,9 +623,8 @@ export default {
const windows = this.$refs.promptWindow;
const prompt = this.prompts.find(p => p.id === id);
if (!prompt) return null;
const label = `${prompt.name}-prompt`;
return Array.isArray(windows)
? windows.find(w => w?.getAttribute('aria-label') === label)
? windows.find(w => w?.dataset.promptId === String(id))
: windows;
},
onPointerDown(e, id, type) {
@@ -685,8 +685,7 @@ export default {
});
// Find the element for this prompt
const windows = this.$refs.promptWindow;
const el = Array.isArray(windows) ? windows.find(w => w?.getAttribute('aria-label') === `${this.prompts.find(p => p.id === id)?.name}-prompt`) : windows;
const el = this.getPromptElement(id);
if (el) this.clampDragOffset(id, el);
},
onPointerEnd(_e, id, type, moveHandler, endHandler) {
@@ -707,10 +706,7 @@ export default {
const pos = this.getPointerPos(e, type);
if (!pos) return;
// Find the window
const windows = this.$refs.promptWindow;
const el = Array.isArray(windows)
? windows.find(w => w?.getAttribute('aria-label') === `${this.prompts.find(p => p.id === id)?.name}-prompt`)
: windows;
const el = this.getPromptElement(id);
if (!el) return;
// Capture current size (if not already fixed, set it)
let sizes = this.sizes;
@@ -819,10 +815,7 @@ export default {
y: start.offsetY + deltaOffsetY,
});
// Clamp to viewport
const windows = this.$refs.promptWindow;
const el = Array.isArray(windows)
? windows.find(w => w?.getAttribute('aria-label') === `${this.prompts.find(p => p.id === id)?.name}-prompt`)
: windows;
const el = this.getPromptElement(id);
if (el) this.clampDragOffset(id, el);
},
onResizeEnd(_e, type, moveHandler, endHandler) {
@@ -6,7 +6,7 @@ import { useSwipeNavigationGestures } from "../useSwipeNavigationGestures.ts";
import { withSetup } from "./mediaTestUtils.ts";
vi.mock("@/store/index.ts", () => ({
state: reactive({ navigation: { enabled: false, previousLink: "", nextLink: "" } }),
state: reactive({ prompts: [], navigation: { enabled: false, previousLink: "", nextLink: "" } }),
getters: {
currentPrompt: () => null,
isPreviewPlaybackQueueNavMode: () => false,
@@ -166,7 +166,7 @@ export function useDoubleTapSeek({
ignoreClickUntil = Date.now() + 500;
return;
}
gestures.clearEdgeTapGestureState();
handleCenterTap(event);
ignoreClickUntil = Date.now() + 500;
};
let edgeClickToggleTimer: ReturnType<typeof setTimeout> | null = null;
@@ -33,7 +33,7 @@ export function useMediaKeyboard(options: MediaKeyboardOptions) {
}
// left/right arrows for seek feedback
if (key === "arrowleft" || key === "arrowright") {
if (!options.player.value) return;
if (!options.player.value || state.prompts.length > 0) return;
event.preventDefault();
options.flashSkipFeedback(key === "arrowleft");
return;
@@ -330,6 +330,7 @@ export function useSwipeNavigationGestures({
// Normal close preview
dismissCloseTimer = setTimeout(() => {
dismissCloseTimer = null;
if (state.prompts.length > 0) return;
onClosePreview();
}, 120);
dismissHintTimer = setTimeout(() => {
@@ -480,7 +481,8 @@ export function useSwipeNavigationGestures({
}
}
if (!swipeGesturesActive.value || event.targetTouches.length !== 1) {
if (!swipeGesturesActive.value || event.touches.length !== 1) {
if (event.touches.length > 1) swipeActiveTouchId = null;
if (edgeKind || edgeDx || edgeDy) {
resetEdgeGestureImmediate();
}
@@ -560,6 +562,10 @@ export function useSwipeNavigationGestures({
event.preventDefault();
return;
}
if (event.touches.length > 0) {
resetEdgeGestureImmediate();
return;
}
// Normal swipe gesture
edgeDx = t.pageX - edgeStartX;
edgeDy = t.pageY - edgeStartY;
@@ -182,6 +182,16 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
let startPreparationId = 0;
let transcodeFallbackAttempted = false;
let transcodeOfferEmitted = false;
interface PendingModeRequest {
mode: string;
playPrime?: ReturnType<typeof primePlay> | null;
}
let pendingModeRequest: PendingModeRequest | null = null;
function takePendingModeRequest(): PendingModeRequest | null {
const request = pendingModeRequest;
pendingModeRequest = null;
return request;
}
let resumeOnGestureArmed = false;
let resumeOnGestureHandler: (() => void) | null = null;
@@ -648,7 +658,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
}
offerLookupPending = false;
console.error("Failed to check transcode sessions:", err);
showTranscodeOffer({ enabled: false, canStart: false, sessions: [] });
showTranscodeOffer({ enabled: true, canStart: true, sessions: [] });
}
}
/** Looks up the session status and shows the offer for it */
@@ -673,7 +683,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
}
offerLookupPending = false;
console.error("Failed to check transcode sessions:", err);
showTranscodeOffer({ enabled: false, canStart: false, sessions: [] });
showTranscodeOffer({ enabled: true, canStart: true, sessions: [] });
}
}
@@ -688,7 +698,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
if (!Number.isFinite(video.duration) || video.duration <= 0) {
return;
}
void offerTranscodePlayback();
void offerTranscodePlayback({ confirmedFailure: true });
}
function syncPlayerAfterTranscodeReady(): void {
@@ -1098,9 +1108,21 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
if (!TRANSCODE_MODES.includes(mode)) {
return;
}
if (mode === transcodeMode.value || transcodeSwitchInProgress.value) {
if (transcodeSwitchInProgress.value) {
pendingModeRequest = { mode, playPrime };
return;
}
if (mode === transcodeMode.value) {
return;
}
if (
TRANSCODE_HLS_MODES.includes(mode) &&
(!getReq()?.source || !getReq()?.path || !transcodeEnabled.value || !resolveViewTokenForTranscode())
) {
syncPlaybackUrl({ transcodeMode: transcodeMode.value });
return;
}
pendingModeRequest = null;
invalidateOfferRequest();
const previousMode = transcodeMode.value;
const wasPlaying = !!player.value?.playing;
@@ -1137,7 +1159,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
}
try {
if (TRANSCODE_HLS_MODES.includes(mode)) {
await startTranscodePlayback({
const started = await startTranscodePlayback({
replaceSessionId,
startSec: player.value?.currentTime ?? 0,
mode,
@@ -1145,6 +1167,12 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
playPrime: wasPlaying ? playPrime : null,
manageSwitchState: false,
});
if (!started.ok && started.reason === "preconditions" && generation === fileGeneration) {
transcodeMode.value = previousMode;
if (previousMode === "native") {
await switchToNativePlayback({ autoplay: wasPlaying });
}
}
} else if (needsTranscodeFirst(transcodeProbeParams())) {
let status: TranscodeStatus | null = null;
try {
@@ -1187,6 +1215,10 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
if (generation === fileGeneration) {
syncPlaybackUrl({ transcodeMode: transcodeMode.value });
}
const next = takePendingModeRequest();
if (next && generation === fileGeneration && next.mode !== transcodeMode.value) {
void switchTranscodeMode(next.mode, { playPrime: next.playPrime });
}
transcodeLog("switchTranscodeMode done", {
mode: transcodeMode.value,
transcodeActive: transcodeActive.value,
@@ -1333,6 +1365,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) {
invalidateOfferRequest();
startPreparationId++;
modeSwitchToken = null;
pendingModeRequest = null;
transcodeSwitchOwner = null;
transcodeSwitchInProgress.value = false;
videoStreamAttached.value = false;
+13 -1
View File
@@ -211,7 +211,9 @@ function attachNativeHls({
return new Promise((resolve, reject) => {
const deadlineMs = resolveAttachDeadlineMs(initialStart, budgetMs);
let settled = false;
let hasPlayed = false;
let timeoutId = null;
const originalPreload = video.getAttribute('preload');
const removeListeners = () => {
clearTimeout(timeoutId);
@@ -221,11 +223,17 @@ function attachNativeHls({
};
const releaseSource = () => {
video.removeAttribute('src');
if (originalPreload === null) {
video.removeAttribute('preload');
} else {
video.setAttribute('preload', originalPreload);
}
video.load();
};
const cleanup = () => {
removeListeners();
video.removeEventListener('error', onError);
video.removeEventListener('playing', onPlaying);
releaseSource();
};
const fail = (error) => {
@@ -262,7 +270,7 @@ function attachNativeHls({
function reportPostReadyError(error) {
const data = { fatal: true, type: 'mediaError', details: 'nativeHlsError', code: error.code, reason: error.message };
const startSec = Number.isFinite(video.currentTime) ? video.currentTime : 0;
const shouldAutoplay = !video.paused && !video.ended;
const shouldAutoplay = hasPlayed ? !video.paused && !video.ended : undefined;
cleanup();
if (error.code === MediaError.MEDIA_ERR_NETWORK && onRecoverPlayback) {
void onRecoverPlayback({ startSec, sessionId, shouldAutoplay })
@@ -278,6 +286,9 @@ function attachNativeHls({
}
onFatal?.(data);
}
function onPlaying() {
hasPlayed = true;
}
function onTimeout() {
transcodeError('native hls attach timed out waiting for readiness', {
playlistURL,
@@ -309,6 +320,7 @@ function attachNativeHls({
video.addEventListener('loadeddata', onReady);
video.addEventListener('canplay', onReady);
video.addEventListener('error', onError);
video.addEventListener('playing', onPlaying);
timeoutId = setTimeout(onTimeout, deadlineMs);
video.preload = 'auto';
video.src = playlistURL;
@@ -334,13 +334,13 @@ export class TranscodePlaybackController {
});
break;
} catch (attachErr) {
const retryable = attachErr?.name === 'AttachTimeoutError'
const retryable = (attachErr?.name === 'AttachTimeoutError' || attachErr?.name === 'NativeHlsError')
&& attachAttempt < MAX_ATTACH_RETRIES
&& this.isCurrentAttempt(attempt);
if (!retryable) {
throw attachErr;
}
transcodeWarn('HLS attach timed out — reattaching', {
transcodeWarn('HLS attach failed before ready — reattaching', {
sessionId: controller.session?.id,
attachAttempt,
});
+1 -4
View File
@@ -23,10 +23,7 @@ export interface LyricsMeta {
export type LyricLines = LyricLine[] & { lrcMeta?: LyricsMeta };
export function isSyncedLyrics(lyrics: LyricLine[]): boolean {
return (
lyrics.length > 0 &&
!lyrics.every((line) => line.timestamp === 0 && !line.words?.some((word) => word.timestamp !== 0))
);
return lyrics.some((line) => !line.untimed);
}
const INLINE_TAG_RE = /<[^>]*>/g;