Skip to content

fix(desktop): make drag & drop work on Windows - #272

Merged
javi11 merged 1 commit into
mainfrom
fix/windows-file-drop
Sep 6, 2026
Merged

javi11 merged 1 commit into
mainfrom
fix/windows-file-drop

Conversation

@javi11

@javi11 javi11 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes Windows drag & drop (#114) without moving to the Wails v3 alpha/beta. The failure was postie's own wiring, not the upstream WebView2 bug the issue assumed.

Root cause

The two platforms reach the same wails:file-drop event by completely different routes:

  • macOS/Linux — the drop is handled natively in the window (darwin/WailsWebView.m performDragOperation:, GTK on Linux) and emits wails:file-drop directly. No JS involved, which is why runtime.OnFileDrop in main.go worked there.
  • Windows — there is no native handler. The only route is JS: a drop listener calls chrome.webview.postMessageWithAdditionalObjects("file:drop:x:y", files), and windows/frontend.go turns that message into wails:file-drop.

That JS listener is installed only inside the JS runtime's OnFileDrop(), which the frontend never called — +page.svelte registered its own drop handler that stops navigation but posts nothing back. So on Windows nothing ever reached Go.

Second, independent blocker: DisableWebViewDrop: true calls chromium.AllowExternalDrag(false) on Windows, so the webview refuses the external drag outright and no JS drop event fires at all.

Changes

  • frontend/src/routes/+page.svelteregisterWailsFileDrop() on mount dynamically imports the Wails runtime and calls OnFileDrop(() => {}, false). The callback is intentionally empty; the work still happens in the Go handler. useDropTarget: false because the default re-checks document.elementFromPoint against --wails-drop-target, which the conditionally rendered drag overlay breaks. OnFileDropOff runs on destroy, guarded by a destroyed flag so a late-resolving import can't register after teardown. Web mode short-circuits before the import.
  • main.goDisableWebViewDrop is now runtime.GOOS != "windows".

Notes

Wails v2.14.0 is out but contains only a WebView2 bootstrapper fix, nothing drag-related. v3 would mean a full API migration (EnableFileDrop, data-file-drop-target, WindowFilesDropped) for a problem we don't have.

Test plan

  • gofmt -l main.go clean, go vet ./... clean, host go build ./... passes
  • bun run build succeeds; the dynamic import resolves
  • bun run check — 2 errors, both pre-existing and in untouched files (ServerSection ServerData.name, DashboardHeader count in MessageObject)
  • Needs a real Windows build to verify behavior — this cannot be confirmed on macOS. Cross-compiling with GOOS=windows fails on unrelated cgo deps (rapidyenc, par2go/internal/parpar).
  • Confirm macOS/Linux drop still works (native path should be untouched)

If the drop lands but the overlay stays stuck visible, that's wails#5780, separate from this fix.

Windows has no native file-drop handler. The only path to the
`wails:file-drop` event is the webview's JS drop listener posting the
dropped files back to Go via postMessageWithAdditionalObjects, which
Wails installs exclusively inside the JS runtime's OnFileDrop(). The
frontend never called it, so the Go-side handler in main.go could never
fire. macOS and Linux handle the drop natively in the window, which is
why it worked there.

Two independent blockers, both fixed:

- Register the JS runtime's OnFileDrop on mount in Wails mode, with
  useDropTarget disabled since the default re-checks elementFromPoint
  against --wails-drop-target and the drag overlay is conditionally
  rendered. Unregister on destroy.
- Stop setting DisableWebViewDrop on Windows, where it calls
  AllowExternalDrag(false) and prevents the webview from receiving the
  external drag at all. macOS and Linux keep it so the webview does not
  handle the file itself.

Refs #114
@javi11
javi11 force-pushed the fix/windows-file-drop branch from d6d5d74 to 33cb660 Compare September 6, 2026 14:10
@javi11
javi11 merged commit e20ff59 into main Sep 6, 2026
4 checks passed
@javi11
javi11 deleted the fix/windows-file-drop branch September 6, 2026 14:15
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