Repository navigation
Commit cbe0944
fix(media): save native menu media downloads and hide loopback links on macOS
Download Video, Audio and Image in WebKit's native context menu saved
nothing. WebKit reports those downloads only to the private
`_webView:contextMenuDidCreateDownload:` (WKNavigationDelegatePrivate,
macOS 12+), which wry 0.57 does not implement, so each download had no
delegate and was cancelled. For the main webview, the method is now
added to wry's navigation delegate class. It attaches a
WKDownloadDelegate to downloads of relay media, which saves them to
~/Downloads under the player Download's name, with `name (n).ext` if
the name is taken. A non-200 response, a non-relay source, or a webview
other than main keeps WebKit's current behaviour.
`<video>` and `<audio>` play from the tokened 127.0.0.1 listener, and
Copy Video Address, Open Video in New Window and Share… hand out that
URL with the token in it. A `willOpenMenu:withEvent:` override on
wry's webview class first calls the inherited method, then removes
those three items, and the separators left behind, from main-webview
media menus only. Play, Picture in Picture, Full Screen, controls and
Download stay. Image and selection menus keep Share….
Both methods are added class-wide, so they check that the webview is
the main one, which leaves Buzz Browser guests unaffected. If a class
already has its own method, as after a wry upgrade, class_addMethod
fails and that part logs and keeps WebKit's behaviour. The collision
naming is extracted from `save_download` into `download_names` and
shared.
Verified by running:
- cargo build, workspace clippy with --all-targets and -D warnings,
and all 716 src-tauri tests pass.
- New unit tests cover menu filtering for the video, image and
selection menus, naming for loopback and buzz-media sources, and
free names when an occupied name or a dangling symlink exists.
- The app launched signed in with communities loaded and logged no
hook-install failures. A native text-selection menu still showed
Share….
Not verified in the running app: the live download and the media menu.
The automated right-click on a video never opened its menu, and I
stopped because the machine was in use. These parts are checked only
by reading code:
- the hooks fire and items are removed;
- a file lands in ~/Downloads;
- whether WebKit downloads buzz-media:// images;
- what partial file is left if a download fails.
Risks: this relies on private WebKit API, which Safari uses and which
has existed since macOS 12. A wry upgrade that implements either method
disables that part, with a log line. Re-check both items on every wry
upgrade.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Matt Toohey <[email protected]>1 parent 67e4049 commit cbe0944
5 files changed
Lines changed: 513 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
925 | 927 | | |
926 | 928 | | |
927 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
928 | 942 | | |
929 | 943 | | |
930 | 944 | | |
| |||
0 commit comments