mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[v2] fix: simplify DragAndDrop fix - remove OnDomReady suppression
The previous fix was over-engineered. It suppressed OnDomReady events on all platforms to prevent multiple calls during file drops. However, users may have legitimate use cases for OnDomReady being called on navigation/reload. This simplified fix: - Keeps the JavaScript setup() that runs on each DOM load to register drag handlers early (preventing browser navigation on file drops) - Keeps the Windows AllowExternalDrag fix for EnableFileDrop+DisableWebViewDrop - Removes the OnDomReady suppression on macOS, Linux, and Windows The core insight is that by preventing browser navigation on file drops via JavaScript, the page won't reload, so OnDomReady won't fire extra times in the problematic scenario anyway. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7ddb49b1d4
commit
ae04fea5b0
7 changed files with 10 additions and 40 deletions
|
|
@ -50,7 +50,6 @@
|
|||
|
||||
@property bool devtoolsEnabled;
|
||||
@property bool defaultContextMenuEnabled;
|
||||
@property bool domReadySent;
|
||||
|
||||
@property (retain) WKUserContentController* userContentController;
|
||||
|
||||
|
|
|
|||
|
|
@ -473,12 +473,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
|||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
||||
// Only send DomReady once to prevent OnDomReady callback from being called
|
||||
// multiple times (e.g., on navigation or page reload)
|
||||
if (!self.domReadySent) {
|
||||
self.domReadySent = YES;
|
||||
processMessage("DomReady");
|
||||
}
|
||||
processMessage("DomReady");
|
||||
}
|
||||
|
||||
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
||||
|
|
|
|||
|
|
@ -469,20 +469,11 @@ gboolean UnFullscreen(gpointer data)
|
|||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
// Flag to track if DomReady has been sent - ensures OnDomReady callback is only called once
|
||||
static gboolean domReadySent = FALSE;
|
||||
|
||||
static void webviewLoadChanged(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer data)
|
||||
{
|
||||
if (load_event == WEBKIT_LOAD_FINISHED)
|
||||
{
|
||||
// Only send DomReady once to prevent OnDomReady callback from being called
|
||||
// multiple times (e.g., on navigation or page reload)
|
||||
if (!domReadySent)
|
||||
{
|
||||
domReadySent = TRUE;
|
||||
processMessage("DomReady");
|
||||
}
|
||||
processMessage("DomReady");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -907,6 +907,10 @@ func (f *Frontend) ExecJS(js string) {
|
|||
}
|
||||
|
||||
func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.ICoreWebView2NavigationCompletedEventArgs) {
|
||||
if f.frontendOptions.OnDomReady != nil {
|
||||
go f.frontendOptions.OnDomReady(f.ctx)
|
||||
}
|
||||
|
||||
if f.frontendOptions.Frameless && f.frontendOptions.DisableResize == false {
|
||||
f.ExecJS("window.wails.flags.enableResize = true;")
|
||||
}
|
||||
|
|
@ -920,12 +924,6 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC
|
|||
}
|
||||
f.hasStarted = true
|
||||
|
||||
// Only call OnDomReady on the first navigation completion to prevent
|
||||
// multiple calls when page reloads or navigates (e.g., during file drops)
|
||||
if f.frontendOptions.OnDomReady != nil {
|
||||
go f.frontendOptions.OnDomReady(f.ctx)
|
||||
}
|
||||
|
||||
// Hack to make it visible: https://github.com/MicrosoftEdge/WebView2Feedback/issues/1077#issuecomment-825375026
|
||||
err := f.chromium.Hide()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import {EventsOn, EventsOff} from "./events";
|
|||
|
||||
const flags = {
|
||||
registered: false,
|
||||
handlersSetup: false,
|
||||
defaultUseDropTarget: true,
|
||||
useDropTarget: true,
|
||||
nextDeactivate: null,
|
||||
|
|
@ -247,9 +246,6 @@ export function OnFileDrop(callback, useDropTarget) {
|
|||
const uDTPT = typeof useDropTarget;
|
||||
flags.useDropTarget = uDTPT === "undefined" || uDTPT !== "boolean" ? flags.defaultUseDropTarget : useDropTarget;
|
||||
|
||||
// Ensure handlers are set up (idempotent - safe to call multiple times)
|
||||
setup();
|
||||
|
||||
let cb = callback;
|
||||
if (flags.useDropTarget) {
|
||||
cb = function (x, y, paths) {
|
||||
|
|
@ -277,16 +273,13 @@ export function OnFileDropOff() {
|
|||
}
|
||||
|
||||
/**
|
||||
* setup installs the drag and drop handlers early to prevent browser navigation
|
||||
* 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() {
|
||||
if (flags.handlersSetup) {
|
||||
return;
|
||||
}
|
||||
flags.handlersSetup = true;
|
||||
window.addEventListener('dragover', onDragOver);
|
||||
window.addEventListener('dragleave', onDragLeave);
|
||||
window.addEventListener('drop', onDrop);
|
||||
|
|
|
|||
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