Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/media player: rename "autoplay" to "play next" to avoid confusion
Adorian Doranbf58f4c460d0
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 8e43168764..11420b0d1f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1199,7 +1199,7 @@"play-mode-title": "Play mode: {{mode}}","play-mode-once": "Play once","play-mode-loop": "Loop",- "play-mode-auto": "Autoplay",+ "play-mode-next": "Play next","rotate": "Rotate","picture-in-picture": "Picture-in-picture","exit-picture-in-picture": "Exit picture-in-picture",diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsxindex d0f958a205..cb54261f2c 100644--- a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx@@ -207,7 +207,7 @@ export function useMediaSessionController(note: FNote, noteContext: NoteContext// every other mounted player (audio or video) so they pause themselves and hand over the OS Media Session.// The slot is *kept* through pause/end (a paused player keeps the session); it's only released when another// player claims it or when this player unmounts (its tab is closed). When a track ends and the parent folder- // opted in (`#mediaNotesPlayMode=auto`), auto-advance to the next sibling: navigation reuses this same media+ // opted in (`#mediaNotesPlayMode=next`), auto-advance to the next sibling: navigation reuses this same media// element (siblings share the type), so playback — and with it the OS session that keeps a backgrounded /// sleeping mobile page alive — continues across the jump rather than the page going idle.useEffect(() => {@@ -397,7 +397,7 @@ export function useMediaPlayMode(noteContext: NoteContext | undefined, mediaRef:}});- // Looping is derived from the mode (auto-advance for "auto" lives in useMediaSessionController's ended handler).+ // Looping is derived from the mode (auto-advance for "next" lives in useMediaSessionController's ended handler).useEffect(() => {const media = mediaRef.current;if (media) media.loop = shouldLoop(mode);diff --git a/apps/client/src/widgets/type_widgets/file/media_play_mode.spec.ts b/apps/client/src/widgets/type_widgets/file/media_play_mode.spec.tsindex 73c4c41bea..2b49f83dfe 100644--- a/apps/client/src/widgets/type_widgets/file/media_play_mode.spec.ts+++ b/apps/client/src/widgets/type_widgets/file/media_play_mode.spec.ts@@ -5,34 +5,34 @@ import { type AutoAdvanceNavigation, getAutoAdvanceTarget, MEDIA_PLAY_MODES, typdescribe("getAutoAdvanceTarget", () => {const nav = (index: number, total: number, nextId: string): AutoAdvanceNavigation => ({ index, total, nextId });- it("advances to the following sibling when the parent is in auto mode", () => {- expect(getAutoAdvanceTarget("auto", nav(1, 3, "b"))).toBe("b");- expect(getAutoAdvanceTarget("auto", nav(2, 3, "c"))).toBe("c");+ it("advances to the following sibling when the parent is in play-next mode", () => {+ expect(getAutoAdvanceTarget("next", nav(1, 3, "b"))).toBe("b");+ expect(getAutoAdvanceTarget("next", nav(2, 3, "c"))).toBe("c");});it("stops at the last sibling instead of wrapping back to the first", () => {- // nextId wraps to the first sibling here, but auto-advance must not loop the folder.- expect(getAutoAdvanceTarget("auto", nav(3, 3, "a"))).toBeNull();+ // nextId wraps to the first sibling here, but advancing must not loop the folder.+ expect(getAutoAdvanceTarget("next", nav(3, 3, "a"))).toBeNull();});- it("does not advance unless the play mode is exactly \"auto\"", () => {+ it("does not advance unless the play mode is exactly \"next\"", () => {const navigation = nav(1, 3, "b");expect(getAutoAdvanceTarget(undefined, navigation)).toBeNull();expect(getAutoAdvanceTarget(null, navigation)).toBeNull();expect(getAutoAdvanceTarget("", navigation)).toBeNull();- expect(getAutoAdvanceTarget("manual", navigation)).toBeNull();- expect(getAutoAdvanceTarget("Auto", navigation)).toBeNull();+ expect(getAutoAdvanceTarget("auto", navigation)).toBeNull();+ expect(getAutoAdvanceTarget("Next", navigation)).toBeNull();});it("does not advance when there is no sibling navigation (a lone item or none)", () => {- expect(getAutoAdvanceTarget("auto", null)).toBeNull();+ expect(getAutoAdvanceTarget("next", null)).toBeNull();});});describe("playModeFromLabel", () => {it("maps the parent's label value to a mode", () => {expect(playModeFromLabel("loop")).toBe("loop");- expect(playModeFromLabel("auto")).toBe("auto");+ expect(playModeFromLabel("next")).toBe("next");});it("treats a missing or unrecognised label as play-once", () => {@@ -48,7 +48,7 @@ describe("playModeToLabel", () => {it("removes the label for play-once and writes the value otherwise", () => {expect(playModeToLabel("once")).toBeNull();expect(playModeToLabel("loop")).toBe("loop");- expect(playModeToLabel("auto")).toBe("auto");+ expect(playModeToLabel("next")).toBe("next");});it("round-trips with playModeFromLabel for every mode", () => {@@ -60,7 +60,7 @@ describe("playModeToLabel", () => {describe("shouldLoop", () => {it("loops only in loop mode", () => {- const looping: Record<MediaPlayMode, boolean> = { once: false, loop: true, auto: false };+ const looping: Record<MediaPlayMode, boolean> = { once: false, loop: true, next: false };for (const mode of MEDIA_PLAY_MODES) {expect(shouldLoop(mode)).toBe(looping[mode]);}diff --git a/apps/client/src/widgets/type_widgets/file/media_play_mode.ts b/apps/client/src/widgets/type_widgets/file/media_play_mode.tsindex 3e8cb0d16b..881420e2a0 100644--- a/apps/client/src/widgets/type_widgets/file/media_play_mode.ts+++ b/apps/client/src/widgets/type_widgets/file/media_play_mode.ts@@ -4,32 +4,32 @@ export const MEDIA_PLAY_MODE_LABEL = "mediaNotesPlayMode";/** {@link MEDIA_PLAY_MODE_LABEL} value that repeats the current note when it ends. */export const MEDIA_PLAY_MODE_LOOP = "loop";-/** {@link MEDIA_PLAY_MODE_LABEL} value that auto-advances to the next sibling when playback ends. */-export const MEDIA_PLAY_MODE_AUTO = "auto";+/** {@link MEDIA_PLAY_MODE_LABEL} value that advances to the next sibling when playback ends. */+export const MEDIA_PLAY_MODE_NEXT = "next";/*** What a media note does when it finishes, configured per folder via {@link MEDIA_PLAY_MODE_LABEL}:- * - `once` — stop (no loop, no auto-advance); the parent carries no label.+ * - `once` — stop (no loop, no advance); the parent carries no label.* - `loop` — repeat the current note; parent label is `"loop"`.- * - `auto` — advance to the next sibling; parent label is `"auto"`.+ * - `next` — advance to the next sibling; parent label is `"next"`.*/-export type MediaPlayMode = "once" | "loop" | "auto";+export type MediaPlayMode = "once" | "loop" | "next";/** All modes, in the order shown in the play-mode menu. */-export const MEDIA_PLAY_MODES: readonly MediaPlayMode[] = [ "once", "loop", "auto" ];+export const MEDIA_PLAY_MODES: readonly MediaPlayMode[] = [ "once", "loop", "next" ];/** Boxicon class for each mode — shown on the button (current mode) and beside each menu item. */export const MEDIA_PLAY_MODE_ICONS: Record<MediaPlayMode, string> = {once: "bx bx-arrow-to-right",loop: "bx bx-repeat",- auto: "bx bx-arrow-from-left"+ next: "bx bx-arrow-from-left"};/** i18n key for each mode's display name. */export const MEDIA_PLAY_MODE_LABEL_KEYS: Record<MediaPlayMode, string> = {once: "media.play-mode-once",loop: "media.play-mode-loop",- auto: "media.play-mode-auto"+ next: "media.play-mode-next"};/** The minimal slice of sibling-navigation state {@link getAutoAdvanceTarget} needs. */@@ -45,7 +45,7 @@ export interface AutoAdvanceNavigation {/** The play mode encoded by a parent's {@link MEDIA_PLAY_MODE_LABEL} value; anything unrecognised is "play once". */export function playModeFromLabel(labelValue: string | null | undefined): MediaPlayMode {if (labelValue === MEDIA_PLAY_MODE_LOOP) return "loop";- if (labelValue === MEDIA_PLAY_MODE_AUTO) return "auto";+ if (labelValue === MEDIA_PLAY_MODE_NEXT) return "next";return "once";}@@ -60,12 +60,12 @@ export function shouldLoop(mode: MediaPlayMode): boolean {}/**- * When a media note finishes playing, the id of the sibling to play next — or `null` to stop. Auto-advance- * happens only when the parent opted in via `#mediaNotesPlayMode=auto`, and only to a *following* sibling: the+ * When a media note finishes playing, the id of the sibling to play next — or `null` to stop. Advancing+ * happens only when the parent opted in via `#mediaNotesPlayMode=next`, and only to a *following* sibling: the* last item stops rather than wrapping back to the first.*/export function getAutoAdvanceTarget(playMode: string | null | undefined, navigation: AutoAdvanceNavigation | null): string | null {- if (playMode !== MEDIA_PLAY_MODE_AUTO || !navigation) {+ if (playMode !== MEDIA_PLAY_MODE_NEXT || !navigation) {return null;}// `nextId` wraps to the first sibling at the end; only advance while a later sibling actually follows.