Skip to content

Fix the Download button doing nothing in the desktop app - #32

Open
dlxkrtjs-ship-it wants to merge 1 commit into
avlp12:mainfrom
dlxkrtjs-ship-it:fix/webview-downloads
Open

Fix the Download button doing nothing in the desktop app#32
dlxkrtjs-ship-it wants to merge 1 commit into
avlp12:mainfrom
dlxkrtjs-ship-it:fix/webview-downloads

Conversation

@dlxkrtjs-ship-it

Copy link
Copy Markdown

In the desktop app (desktop.py / the DMG build), the Download buttons on
generated 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:

  1. ALLOW_DOWNLOADS is off. This is the actual cause. pywebview's setting
    defaults to False, and the cocoa backend then cancels any navigation it
    can't render itself — webView_decidePolicyForNavigationAction_ only returns
    WKNavigationActionPolicyDownload when the setting is on, and
    decidePolicyForNavigationResponse falls through to
    WKNavigationResponsePolicyCancel. So the click resolves and is then dropped
    on the floor. desktop.py now opts in; pywebview's DownloadDelegate puts up
    a Save panel pointed at ~/Downloads.

  2. The anchor was detached. Both handlers built an <a> with
    document.createElement and called .click() without inserting it. That's
    not 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 for
    the click and removes it afterwards.

  3. Result cards link to a data: URI. WKWebView won't download those even
    with the policy enabled. _gallery_save now returns the ids it wrote and the
    done event carries them as ids, so a card links to its already-saved
    /api/gallery/<id>.png. The data URI remains as the fallback for when the
    gallery write failed.

Changes

  • studio/desktop.py — set webview.settings["ALLOW_DOWNLOADS"] = True before
    the window is created, guarded so an older pywebview can't break startup.
  • studio/server.py_gallery_save returns the written ids; the done event
    gains an ids field (empty list if the best-effort save raised).
  • web/index.html — shared saveAs() helper; renderCard takes the gallery id
    and 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

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>
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