mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
Merge ae04fea5b0 into 4d0abeb37c
This commit is contained in:
commit
7ce86c3227
6 changed files with 40 additions and 14 deletions
|
|
@ -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!")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
Loading…
Add table
Add a link
Reference in a new issue