From a22876717119498299b3e425bf82fafc152a5880 Mon Sep 17 00:00:00 2001 From: Nabheet Sandhu Date: Fri, 20 Nov 2026 18:25:06 -0700 Subject: [PATCH] chore: remove autoplay, remember and the close RPC The panel should open only when asked. `source`/`autoplay`/`remember` existed to open on load, which surprised users and is now covered by the message marker. `/media` requires a path again, and the storage the old path needed is gone. The `close` RPC method goes with it: escape closes the panel in the TUI, and a script can open another clip instead of closing the current one. --- CHANGELOG.md | 11 ++++++++++ README.md | 49 ++++++++++++++++---------------------------- src/index.ts | 4 ---- src/options.ts | 16 --------------- src/rpc.ts | 15 -------------- src/tui.tsx | 47 +++--------------------------------------- test/options.test.ts | 15 -------------- 7 files changed, 32 insertions(+), 125 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e24f0..c6db638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.1.15 + +Removals. The panel now opens only when asked. + +- Remove: `source`, `autoplay` and `remember`. The panel no longer opens on + load, and `/media` requires a path. That path was the only one that could + surprise a user, and the marker replaced it for the agent case. +- Remove: the `close` RPC method. `escape` closes the panel locally and always + did; a script that opened a clip can open another one instead. +- Docs: one "Ways to open" description instead of four drifting copies. + ## 0.1.14 - Fix: install docs implied both config files were required. They are not: diff --git a/README.md b/README.md index 4007c04..c54f9e3 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,6 @@ Add options by editing the `cli.json` entry: } ``` -With `source` set and `autoplay` left on, the panel opens by itself once a -session is on screen. - ## Example Make a clip to try it with, so no media of your own is needed: @@ -80,25 +77,18 @@ Make a clip to try it with, so no media of your own is needed: ffmpeg -f lavfi -i "testsrc=size=320x240:rate=24:duration=4" -pix_fmt yuv420p /tmp/demo.mp4 ``` -Point `cli.json` at it, as in the install example, with `"source": "/tmp/demo.mp4"`, -then start OpenCode and open a session. The panel opens on its own: +Then run `/media /tmp/demo.mp4` in a session: ```text demo.mp4 · 12 fps · 7/48 · space pause · f fullscreen · esc close ``` -48 frames, because the request is 12 frames per second over 4 seconds; the source +48 frames, because frames are extracted at `fps` (12) over 4 seconds; the source clip's own frame rate does not change that. The line above the frames is the whole -interface: the file name, the frame rate in use, the current frame, and the keys. -`space` pauses, `f` takes the full window, and `esc` closes the panel. - -Without a `source`, ask for the file instead: - -```text -/media /tmp/demo.mp4 -``` +interface: file name, frame rate in use, current frame, keys. `space` pauses, `f` +takes the full window, `esc` closes. -The panel belongs to a session, so opening a file from the home screen reports +The panel belongs to a session, so asking for a file from the home screen reports "Open a session first" and opens nothing. ## Use @@ -141,7 +131,8 @@ The body is an envelope: the method's own arguments go under `input`. A body of service authenticates with HTTP Basic: username `opencode` and the password in `service.json`, over the channel's port (`49374` for `latest`, `0xc0de`). -Every open, including `/media` and autoplay, travels through this RPC: the TUI +Every open, including `/media` and the message marker, travels through this +RPC: the TUI part calls it, the server part emits, and the TUI renders the event. The plugin never shells out. ``` @@ -156,18 +147,15 @@ exactly like typing the command before the panel exists. ## Options -| Option | Default | Meaning | -| ---------------- | ----------- | ----------------------------------------------- | -| `source` | none | File path or URL opened on start. | -| `autoplay` | `true` | Open the panel on start when a source is known. | -| `remember` | `false` | Reopen the last clip played on start. | -| `fps` | `12` | Frames played per second, 1 to 30. | -| `width` | `44` | Panel width in cells, 4 pixels each. | -| `loop` | `true` | Restart after the last frame. | -| `maxFrames` | `300` | Cap on extracted frames, 1 to 2000. | -| `ffmpeg` | `ffmpeg` | Binary name or absolute path. | -| `cacheDirectory` | system temp | Root directory for extracted frames. | -| `presentation` | `panel` | `panel` or `fullscreen`. | +| Option | Default | Meaning | +| ---------------- | ----------- | ------------------------------------ | +| `fps` | `12` | Frames played per second, 1 to 30. | +| `width` | `44` | Panel width in cells, 4 pixels each. | +| `loop` | `true` | Restart after the last frame. | +| `maxFrames` | `300` | Cap on extracted frames, 1 to 2000. | +| `ffmpeg` | `ffmpeg` | Binary name or absolute path. | +| `cacheDirectory` | system temp | Root directory for extracted frames. | +| `presentation` | `panel` | `panel` or `fullscreen`. | Frame height follows the source aspect ratio. @@ -179,8 +167,8 @@ Frame height follows the source aspect ratio. 3. A timer advances the frame index, and the panel sets its `` source to the next entry. -Opening is one path. `/media`, autoplay and a message marker all ask the -plugin, the plugin calls its own RPC (`context.client.rpc(Media).open`), the +Opening is one path. `/media`, a message marker and an external RPC call all ask +the plugin, the plugin calls its own RPC (`context.client.rpc(Media).open`), the server part emits, and the TUI's subscription renders. Nothing shells out, and if the server part is not loaded the call rejects and the local opener runs instead. @@ -215,7 +203,6 @@ directory under `cacheDirectory` to fetch it again. | Toast: `Could not run ffmpeg` | ffmpeg is not on the TUI's `PATH`; set `ffmpeg` to a full path. | | Toast: `Open a session first` | The panel only exists inside a session. | | Toast: `ffmpeg failed on ...` | The file is not media ffmpeg can decode. | -| No autoplay | No `source` set and `remember` off, or no session is open yet. | | Panel opens, frame blank | The terminal has no image support. | | Panel shows one frame, frozen | The plugin was hot-swapped into a running session by a config | | counter, `escape` ignored | edit; restart the TUI so it mounts fresh. | diff --git a/src/index.ts b/src/index.ts index 620849a..3f56657 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,10 +25,6 @@ export default Plugin.define({ await registration.events.emit("open", { source }); return { queued: true }; }, - close: async () => { - await registration.events.emit("close", {}); - return { queued: true }; - }, }); }, }); diff --git a/src/options.ts b/src/options.ts index 4904157..3990f84 100644 --- a/src/options.ts +++ b/src/options.ts @@ -8,8 +8,6 @@ export type PanelPresentation = "panel" | "fullscreen"; export interface MediaOptions { - /** File path or URL played on start. Without it the panel opens from a command. */ - readonly source: string | undefined; /** Frames played per second. */ readonly fps: number; /** Panel width in terminal cells. Pixel width is four times this. */ @@ -18,10 +16,6 @@ export interface MediaOptions { readonly loop: boolean; /** Upper bound on extracted frames, so a long clip cannot exhaust memory. */ readonly maxFrames: number; - /** Open the panel on start when a source is known. */ - readonly autoplay: boolean; - /** Remember the last clip played and reopen it on start. */ - readonly remember: boolean; /** ffmpeg binary name or absolute path. */ readonly ffmpeg: string; /** Root directory for extracted frames. Defaults to the system temp directory. */ @@ -31,13 +25,10 @@ export interface MediaOptions { } export const DEFAULT_MEDIA_OPTIONS: MediaOptions = { - source: undefined, fps: 12, width: 44, loop: true, maxFrames: 300, - autoplay: true, - remember: false, ffmpeg: "ffmpeg", cacheDirectory: undefined, presentation: "panel", @@ -70,23 +61,16 @@ const booleanOr = (value: unknown, fallback: boolean): boolean => export function normalizeOptions(raw: Readonly> | undefined): MediaOptions { const input = raw ?? {}; - const source = - typeof input.source === "string" && input.source.trim() !== "" - ? input.source.trim() - : undefined; const cacheDirectory = typeof input.cacheDirectory === "string" && input.cacheDirectory.trim() !== "" ? input.cacheDirectory.trim() : undefined; return { - source, fps: numberOr(input.fps, DEFAULT_MEDIA_OPTIONS.fps, 1, 30), width: numberOr(input.width, DEFAULT_MEDIA_OPTIONS.width, 8, 120), loop: booleanOr(input.loop, DEFAULT_MEDIA_OPTIONS.loop), maxFrames: numberOr(input.maxFrames, DEFAULT_MEDIA_OPTIONS.maxFrames, 1, 2000), - autoplay: booleanOr(input.autoplay, DEFAULT_MEDIA_OPTIONS.autoplay), - remember: booleanOr(input.remember, DEFAULT_MEDIA_OPTIONS.remember), ffmpeg: textOr(input.ffmpeg, DEFAULT_MEDIA_OPTIONS.ffmpeg), cacheDirectory, presentation: input.presentation === "fullscreen" ? "fullscreen" : "panel", diff --git a/src/rpc.ts b/src/rpc.ts index 09947f4..ddee1ea 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -31,18 +31,6 @@ const definition = Rpc.define({ additionalProperties: false, }, }, - close: { - input: { - type: "object", - additionalProperties: false, - }, - output: { - type: "object", - properties: { queued: { type: "boolean" } }, - required: ["queued"], - additionalProperties: false, - }, - }, }, events: { open: { @@ -53,9 +41,6 @@ const definition = Rpc.define({ additionalProperties: false, }, }, - close: { - schema: { type: "object", additionalProperties: false }, - }, }, }); diff --git a/src/tui.tsx b/src/tui.tsx index d1f40e8..ac110ff 100644 --- a/src/tui.tsx +++ b/src/tui.tsx @@ -8,7 +8,6 @@ import { Media } from "./rpc"; /** Opening name for this plugin's panel. Shared selection value, not a registry key. */ const PANEL = "media.panel"; -const STORAGE = "media"; // File names and ffmpeg messages reach the renderer as text. Replace control // characters so neither can inject a terminal escape sequence. @@ -91,7 +90,6 @@ export default Plugin.define({ id: PANEL, setup(context) { const options = normalizeOptions(context.options); - const [saved, save] = context.storage.store(STORAGE, { initial: { source: "" } }); const [clip, setClip] = createSignal(); const [index, setIndex] = createSignal(0); const [paused, setPaused] = createSignal(false); @@ -162,17 +160,6 @@ export default Plugin.define({ return false; } - if (options.remember) { - void save((draft) => { - draft.source = source; - }).catch(() => { - context.ui.toast.show({ - variant: "warning", - title: "Media panel", - message: "Could not save the last clip.", - }); - }); - } return true; } @@ -187,9 +174,8 @@ export default Plugin.define({ palette: true, slash: { name: "media", aliases: ["anim"], arguments: true }, run: (input) => { - const given = input?.trim() ?? ""; - const source = given === "" ? options.source : given; - if (source === undefined) { + const source = input?.trim() ?? ""; + if (source === "") { void context.ui.dialog.alert({ title: "Media panel", message: "Pass a file path or URL, for example: /media /home/user/clip.mp4", @@ -233,7 +219,7 @@ export default Plugin.define({ // and this subscriber is what opens it. // Every open goes through the server: `open` below calls the RPC, the // server emits, and this subscriber renders. One path for the slash - // command, autoplay and any external caller, and no shell or CLI in it. + // command, the message marker and any external caller, and no shell in it. // If the server part is not loaded the call rejects and the local opener // runs instead, so a TUI-only install keeps working. const remote = context.client.rpc(Media); @@ -250,9 +236,6 @@ export default Plugin.define({ } Promise.resolve(call({ source })).catch(() => show(source)); } - const stopClose = remote.events.on("close", () => { - context.ui.panel.close(); - }); // A marker in a finished message opens a clip without any shell command: // the client already receives session text, so the plugin is the one that @@ -266,34 +249,10 @@ export default Plugin.define({ if (match?.[1]) open(match[1]); }); - const remembered = options.remember ? saved.source.trim() : ""; - const initial = options.source ?? (remembered === "" ? undefined : remembered); - let autoplay: ReturnType | undefined; - - if (options.autoplay && initial !== undefined) { - let attempts = 0; - autoplay = setInterval(() => { - attempts += 1; - if (context.ui.router.current().type === "session") { - if (autoplay) clearInterval(autoplay); - autoplay = undefined; - open(initial); - return; - } - // Give up after two minutes: no session was opened. - if (attempts > 240 && autoplay) { - clearInterval(autoplay); - autoplay = undefined; - } - }, 500); - } - return () => { stopTicker(); stopOpen(); - stopClose(); stopMarker(); - if (autoplay) clearInterval(autoplay); unregister(); }; }, diff --git a/test/options.test.ts b/test/options.test.ts index d1ca68e..71cf3d7 100644 --- a/test/options.test.ts +++ b/test/options.test.ts @@ -6,14 +6,6 @@ describe("normalizeOptions", () => { expect(normalizeOptions(undefined)).toEqual(DEFAULT_MEDIA_OPTIONS); }); - it("keeps a trimmed source and ignores an empty one", () => { - expect(normalizeOptions({ source: " /home/user/clip.mp4 " }).source).toBe( - "/home/user/clip.mp4", - ); - expect(normalizeOptions({ source: " " }).source).toBeUndefined(); - expect(normalizeOptions({ source: 7 }).source).toBeUndefined(); - }); - it("clamps numbers into the renderable range", () => { expect(normalizeOptions({ fps: 0 }).fps).toBe(1); expect(normalizeOptions({ fps: 999 }).fps).toBe(30); @@ -35,13 +27,6 @@ describe("normalizeOptions", () => { expect(normalizeOptions({ presentation: "window" }).presentation).toBe("panel"); }); - it("treats autoplay and remember as opt-out and opt-in respectively", () => { - expect(normalizeOptions({ autoplay: false }).autoplay).toBe(false); - expect(normalizeOptions({ autoplay: "yes" }).autoplay).toBe(true); - expect(normalizeOptions({ remember: true }).remember).toBe(true); - expect(normalizeOptions({}).remember).toBe(false); - }); - it("keeps a custom ffmpeg path and cache directory", () => { const options = normalizeOptions({ ffmpeg: "/opt/homebrew/bin/ffmpeg",