This commit is contained in:
Lea Anthony 2026-03-04 13:34:19 +01:00 committed by GitHub
commit 7ce86c3227
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 14 deletions

View file

@ -488,7 +488,13 @@ func (f *Frontend) setupChromium() {
chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg)
}
if f.frontendOptions.DragAndDrop != nil && f.frontendOptions.DragAndDrop.DisableWebViewDrop {
// Only disable external drag if DisableWebViewDrop is true AND EnableFileDrop is false.
// When EnableFileDrop is true, we need to allow external drag events so that the
// JavaScript handlers can receive file drop events. The JavaScript will prevent
// the default browser behavior (navigating to the dropped file).
if f.frontendOptions.DragAndDrop != nil &&
f.frontendOptions.DragAndDrop.DisableWebViewDrop &&
!f.frontendOptions.DragAndDrop.EnableFileDrop {
if err := chromium.AllowExternalDrag(false); err != nil {
f.logger.Warning("WebView failed to set AllowExternalDrag to false!")
}

View file

@ -245,9 +245,6 @@ export function OnFileDrop(callback, useDropTarget) {
const uDTPT = typeof useDropTarget;
flags.useDropTarget = uDTPT === "undefined" || uDTPT !== "boolean" ? flags.defaultUseDropTarget : useDropTarget;
window.addEventListener('dragover', onDragOver);
window.addEventListener('dragleave', onDragLeave);
window.addEventListener('drop', onDrop);
let cb = callback;
if (flags.useDropTarget) {
@ -274,3 +271,16 @@ export function OnFileDropOff() {
EventsOff("wails:file-drop");
flags.registered = false;
}
/**
* setup installs the drag and drop handlers to prevent browser navigation
* when files are dropped. This is called from the runtime initialization to ensure
* handlers are in place before the user has a chance to drop files.
* The actual file processing only happens when enableWailsDragAndDrop flag is true.
* This runs on every DOM load to ensure handlers are always registered.
*/
export function setup() {
window.addEventListener('dragover', onDragOver);
window.addEventListener('dragleave', onDragLeave);
window.addEventListener('drop', onDrop);
}

View file

@ -216,4 +216,10 @@ window.addEventListener('contextmenu', function(e) {
}
});
// Setup drag and drop handlers early to prevent browser navigation when files are dropped.
// This must be done before the user has a chance to drop files on the window.
// The actual file processing only happens when enableWailsDragAndDrop flag is set to true
// by the backend (via runtime:ready response).
DragAndDrop.setup();
window.WailsInvoke("runtime:ready");

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long