Repository navigation
ariadne: Save image... and Save video... in a picture's context menu, and (save-url) (§5.29) - #1533
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 areimage:widgets bound to txwtf's/uploads/...URLs, and its videos arevideo:widgets with controls.What the user gets
image:whose picture comes from a URL or a file has Save image... in its context menu. Avideo:with controls has Save video.... As with §5.28's Copy, the document asks for nothing.fullscreen: true, or a clickable group around it).controls: false, or a video URL in animage:),audio:,background:, and button and tray icons.auth:credential. Withoutauth:, they come through the app's HTTP cache, so a picture just drawn is not downloaded again. This usesImageCache::fetch, which also uses a fetcher a host installed.sniff_mime). txwtf's/uploads/<id>holding a PNG becomes<id>.png, and aphoto.jpgthat holds a PNG becomesphoto.png.What each host does
arigl, cvcGL apps)Backend::ask_save_path, the same SDL dialog API asfile-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.<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'sclipboard::arm.ari), and a GL window without SDL$XDG_DOWNLOAD_DIR, thenuser-dirs.dirs, then~/Downloads. An existing file is never overwritten (cat (1).png). A notification (§5.24) names the whole path.Could not save NAME: WHY. A cancelled dialog does nothing.Runtime::set_save_dirlets 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}.{ok cancelled name size error}. The path is never in the reply; the notification tells the user where the file went.(has? "save-url")is true wherever there is a backend.docs/STATE_EXEC_THREADED.mdhas its row.How a document opts out
Add
save: falseto animage:or avideo:. That leaves Save out of its menu. It is in the loader and inari.v1.schema.json.For backends
Backend::item_save(MediaSave)is called right after a picture that offers Save, the wayset_tooltipis.media_save_chosen(and, in arigl-web,media_save_preparewhen the menu opens). The core takes them each drain withtake_media_saves.Backend::ask_save_pathis the host's own Save dialog.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 newAriadneMediaSave.*cases (types, names, a new file never over another, the Downloads folder) andAriadneSaveUrl.*(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, includingAPicturesMenuSavesItIntoTheDownloadsFolder. 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, includingAriadneIsolatedDocs.SaveUrlAsksForAPathOnTheFramesThread. To run it here I commented out its threedeath_test_stylelines; 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 withupload.pngandSave 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-ClipboardthenGet-Clipboardgives nothing), so CI's runs are what count for those.ariglon Windows: a document called(save-url "file://upload")on a JPEG with no extension in its name.upload, with Explorer hiding extensions).Downloads\upload.jpgwas written with the source's exact bytes (SHA-256 matched).cvcgl_imgui_context_menu.on_tickhandler that parks insave-urlgets its guard write lost and calls it again. Call it from an action, asfile-pickis called. §5.29 says so.XDG_DOWNLOAD_DIR/user-dirs.dirscase runs on POSIX only, so only CI runs it.arigl_web_save.mjsis 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 iscat.png, it has the server's bytes, and the link was clicked inside the pointer release. Then the button'ssave-urldownloadsthe clip.webm, and on ari.html Tab plus Enter downloads it too.ftxui. All 8 checks pass, andarigl_web_clipboard.mjspasses on the same build.TvisionBackend : FtxuiBackend); CI covers it.