Skip to content

ariadne: Save image... and Save video... in a picture's context menu, and (save-url) (§5.29) - #1533

Merged
transfix merged 3 commits into
masterfrom
feat/ariadne-save-media
Nov 25, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/ariadne-save-media

Conversation

@transfix

@transfix transfix commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

A user can now save a picture or a video they see to disk from its right-click menu, in every host. Documents can also offer their own Save button with a new verb, (save-url URL [OPTS]). This builds on the §5.28 context menu (#1476), which shipped in 4.0.8, so this lands in the release after it (4.0.9). nicotina needs no change to get the menu items. Its pictures are image: widgets bound to txwtf's /uploads/... URLs, and its videos are video: widgets with controls.

What the user gets

  • An image: whose picture comes from a URL or a file has Save image... in its context menu. A video: with controls has Save video.... As with §5.28's Copy, the document asks for nothing.
  • The menu opens with a right-click, or a long press on a touch screen. In a terminal, Shift+F10 or the Menu key opens it on a picture that takes the focus (fullscreen: true, or a clickable group around it).
  • No Save: a picture the host published by name, a decorative video (controls: false, or a video URL in an image:), audio:, background:, and button and tray icons.
  • The bytes are fetched the way the widget's own fetch got them: the host's network and allowlist, and the widget's auth: credential. Without auth:, they come through the app's HTTP cache, so a picture just drawn is not downloaded again. This uses ImageCache::fetch, which also uses a fetcher a host installed.
  • The file's name is the last part of the URL's path. Its extension comes from what the bytes are (sniff_mime). txwtf's /uploads/<id> holding a PNG becomes <id>.png, and a photo.jpg that holds a PNG becomes photo.png.

What each host does

Host Save
ImGui, natively (arigl, cvcGL apps) SDL3's Save dialog (Backend::ask_save_path, the same SDL dialog API as file-pick's Open). It opens in the Downloads folder with the name filled in and a filter for the file's type. The core writes the file there off the frame and posts a notification, Saved NAME to PATH. One dialog at a time.
arigl-web A browser download: a Blob and an <a download>. The page fetches the bytes as soon as the menu opens (media_save_prepare). The page's own pointer release over Save image... then clicks the link inside the click, which Safari requires. This is the same approach as §5.28's clipboard::arm.
ari.html The same download, started when the bytes arrive.
FTXUI and tvision (ari), and a GL window without SDL A new file in the user's Downloads folder. That folder is the Windows known folder; elsewhere $XDG_DOWNLOAD_DIR, then user-dirs.dirs, then ~/Downloads. An existing file is never overwritten (cat (1).png). A notification (§5.24) names the whole path.
  • A failed menu save posts an error notification, Could not save NAME: WHY. A cancelled dialog does nothing.
  • Runtime::set_save_dir lets a host name a folder other than Downloads.

The verb

(save-url URL [OPTS]) does the same as the menu's Save. OPTS is {name, mime, auth}.

  • The program parks until the save finishes, then gets {ok cancelled name size error}. The path is never in the reply; the notification tells the user where the file went.
  • A failure is a reply, as with the http verbs. A misused option is an error at the call.
  • (has? "save-url") is true wherever there is a backend.
  • Values stay typed: the reply is a state_exec dict, with no JSON anywhere.
  • The verb binds as it is in every group. Its program hands the save to the Runtime's save hub under a lock, and the drain starts it on the frame's thread. docs/STATE_EXEC_THREADED.md has its row.

How a document opts out

Add save: false to an image: or a video:. That leaves Save out of its menu. It is in the loader and in ari.v1.schema.json.

For backends

  • Backend::item_save(MediaSave) is called right after a picture that offers Save, the way set_tooltip is.
  • The backend hands the user's choice back with media_save_chosen (and, in arigl-web, media_save_prepare when the menu opens). The core takes them each drain with take_media_saves.
  • Backend::ask_save_path is the host's own Save dialog.
  • No new process-wide state: the queue lives on the Backend object, the save hub on the Runtime, and the Save dialog on the ImGuiBackend.

The docs are in docs/ARIADNE.md §5.29. It also adds a row to §5.28's table and pointers from §5.11, §5.13 and §10.8.

Tested locally (Windows, MSVC, cvcpkg prefixes)

  • ariadne_files_test: 23/23. That includes the new AriadneMediaSave.* cases (types, names, a new file never over another, the Downloads folder) and AriadneSaveUrl.* (the host's dialog, a second dialog refused, a cancel, no dialog, a failure, misuse, a credential under the host's policy).
  • ariadne_ftxui_test: 120/120, including APicturesMenuSavesItIntoTheDownloadsFolder. That case covers Save image... and Save video..., a new file beside one already there, the notification, save: false, a decorative video, and Shift+F10.
  • ariadne_runtime_test: 360/360, including AriadneIsolatedDocs.SaveUrlAsksForAPathOnTheFramesThread. To run it here I commented out its three death_test_style lines; that is this box's shared-gtest link problem, and the change is not in the PR.
  • cvcgl_imgui_context_menu: the new Save image... block passes (right-click, the item, the dialog asked with upload.png and Save image, the file written where the test's dialog said). Its 16 §5.28 clipboard checks fail on this box because this session's Windows clipboard holds no text (Set-Clipboard then Get-Clipboard gives nothing), so CI's runs are what count for those.
  • By hand, native arigl on Windows: a document called (save-url "file://upload") on a JPEG with no extension in its name.
    • SDL's Save dialog opened titled "Save image", in Downloads, with the filter "Image (.jpg)" and the name filled in (upload, with Explorer hiding extensions).
    • On Save, Downloads\upload.jpg was written with the source's exact bytes (SHA-256 matched).
    • I answered the dialog with a script (Win32 messages and UI Automation), not by clicking. The right-click menu itself is covered by cvcgl_imgui_context_menu.
    • One finding from that test: an on_tick handler that parks in save-url gets its guard write lost and calls it again. Call it from an action, as file-pick is called. §5.29 says so.
  • The XDG_DOWNLOAD_DIR / user-dirs.dirs case runs on POSIX only, so only CI runs it.
  • arigl_web_save.mjs is new and runs in ci.yml's arigl-web job, after the clipboard test. It right-clicks the picture, walks to the armed Save item and checks four things: the download is cat.png, it has the server's bytes, and the link was clicked inside the pointer release. Then the button's save-url downloads the clip.webm, and on ari.html Tab plus Enter downloads it too.
    • I ran it locally, in Chrome, against a lean arigl-web build of this branch. The deps came from cvcpkg: the arigl-web recipe's wasm deps plus ftxui. All 8 checks pass, and arigl_web_clipboard.mjs passes on the same build.
  • tvision is not buildable on this box. It uses the FTXUI menus (TvisionBackend : FtxuiBackend); CI covers it.

… and (save-url) (§5.29)

An image: whose picture comes from a URL or a file has Save image... in the
context menu every host draws (§5.28), and a video: with controls has Save
video.... The document asks for nothing; `save: false` on the widget leaves it
out. A host-published picture, a decorative video, audio, backgrounds, button
and tray icons have none.

The bytes are fetched as the widget's own fetch got them: the host's network
and allowlist, the widget's auth: credential, through the app's HTTP cache
without one (ImageCache::fetch). The file is named from the URL's last path
part, with the extension of what the bytes are (sniff_mime), so txwtf's
/uploads/<id> holding a PNG is <id>.png. Then:

- ImGui natively (arigl, cvcGL apps): SDL3's Save dialog
  (Backend::ask_save_path), opened in the Downloads folder with the name
  filled in; the core writes the file there off the frame, one dialog at a time.
- arigl-web and ari.html: a browser download, a Blob and an <a download>.
  arigl-web fetches the bytes when the menu opens (media_save_prepare) and the
  page's own pointer release over Save image... clicks the link, inside the
  click, as Safari requires (as §5.28's clipboard::arm does).
- FTXUI and tvision (ari), and a GL window without SDL: a new file in the
  user's Downloads folder (the Windows known folder; $XDG_DOWNLOAD_DIR, then
  user-dirs.dirs, then ~/Downloads), never over one there ("cat (1).png").

A native save posts a notification naming the path; a failed menu save posts
an error. (save-url URL [OPTS]) with name, mime and auth does the same for a
document's own Save button. It parks its program and answers
{ok cancelled name size error}, never the path; (has? "save-url") is true
wherever there is a backend. It binds as it is in every group: its program
hands the save to the Runtime's hub, and the drain starts it on the frame's
thread. Runtime::set_save_dir names another folder than Downloads.

Tests: ariadne_files_test's AriadneMediaSave.* and AriadneSaveUrl.*;
ariadne_ftxui_test's APicturesMenuSavesItIntoTheDownloadsFolder;
ariadne_runtime_test's AriadneIsolatedDocs.SaveUrlAsksForAPathOnTheFramesThread;
cvcgl_imgui_context_menu's Save image... block; and arigl_web_save.mjs in
headless Chrome, added to ci.yml's arigl-web job.
…until a download begins

ImGui's button is not where a fixed point guessed. Run locally against a lean
arigl-web of this branch in Chrome: all eight checks pass, the menu's download
clicked inside the pointer release.
@transfix
transfix merged commit 4b37bfd into master Nov 25, 2026
30 of 31 checks passed
@transfix
transfix deleted the feat/ariadne-save-media branch November 25, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant