Fix the Download button doing nothing in the desktop app - #32
Open
dlxkrtjs-ship-it wants to merge 1 commit into
Open
Fix the Download button doing nothing in the desktop app#32dlxkrtjs-ship-it wants to merge 1 commit into
dlxkrtjs-ship-it wants to merge 1 commit into
Conversation
In the native window the image Download buttons were inert — no file, no save panel, no error. Three things stacked up, all specific to WKWebView: - pywebview's ALLOW_DOWNLOADS setting defaults to False, and with it off the cocoa backend cancels any navigation it can't render itself. That is the actual cause: the click was resolved, then dropped on the floor. desktop.py now opts in, so pywebview puts up a Save panel pointed at ~/Downloads. - A detached <a> is not a navigation action, so its click() never reaches the download policy at all. The new saveAs() helper puts the anchor in the document for the click and takes it out again. - Result cards are rendered from a data: URI, which WKWebView will not download even with the policy on. _gallery_save now returns the ids it wrote and the done event carries them, so a card links to its saved /api/gallery/<id>.png instead — the data URI stays only as the fallback for when the gallery write failed. Browser mode was never broken and behaves the same as before. Verified on macOS 15 (WKWebView, pywebview 6.2.1): both the gallery and the result-card buttons now open the Save panel and write the PNG. I left the version bump and the changelog entry alone — 0.9.2 has no CHANGELOG section yet, so that seemed yours to place. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
In the desktop app (
desktop.py/ the DMG build), the Download buttons ongenerated images and on gallery items do nothing — no file, no save panel, no
error in the console. Clicking just silently drops. Browser mode
(
python3 app.py) is unaffected.Three separate things stack up here, all specific to WKWebView:
ALLOW_DOWNLOADSis off. This is the actual cause. pywebview's settingdefaults to
False, and the cocoa backend then cancels any navigation itcan't render itself —
webView_decidePolicyForNavigationAction_only returnsWKNavigationActionPolicyDownloadwhen the setting is on, anddecidePolicyForNavigationResponsefalls through toWKNavigationResponsePolicyCancel. So the click resolves and is then droppedon the floor.
desktop.pynow opts in; pywebview'sDownloadDelegateputs upa Save panel pointed at
~/Downloads.The anchor was detached. Both handlers built an
<a>withdocument.createElementand called.click()without inserting it. That'snot a navigation action, so it never reaches the download policy even with
the setting on. The new
saveAs()helper puts the anchor in the document forthe click and removes it afterwards.
Result cards link to a
data:URI. WKWebView won't download those evenwith the policy enabled.
_gallery_savenow returns the ids it wrote and thedoneevent carries them asids, so a card links to its already-saved/api/gallery/<id>.png. The data URI remains as the fallback for when thegallery write failed.
Changes
studio/desktop.py— setwebview.settings["ALLOW_DOWNLOADS"] = Truebeforethe window is created, guarded so an older pywebview can't break startup.
studio/server.py—_gallery_savereturns the written ids; thedoneeventgains an
idsfield (empty list if the best-effort save raised).web/index.html— sharedsaveAs()helper;renderCardtakes the gallery idand prefers the http URL.
Testing
macOS 15, Apple silicon, pywebview 6.2.1. Before: both buttons inert. After:
both open the Save panel and write the PNG. Browser mode re-checked and
unchanged.
Not included
No version bump and no CHANGELOG entry — 0.9.2 doesn't have a CHANGELOG section
yet, so that felt like yours to place. Happy to add one in whatever shape you
want.
🤖 Generated with Claude Code