Skip to content

Commit d77b37b

Browse files
leaanthonyclaude
andcommitted
Replace fmt.Printf debug statements with globalApplication.debug
Replace all fmt.Printf debug logging statements in drag-and-drop functionality with proper globalApplication.debug calls. This provides: - Consistent logging with the rest of the application - Proper key-value structured logging - Better integration with the application's logging system - Cleaner debug output format Changes: - application_darwin.go: Replace 2 fmt.Printf calls - webview_window.go: Replace 6 fmt.Printf calls - webview_window_windows.go: Replace 13 fmt.Printf calls - Remove unused fmt import from application_darwin.go All debug messages maintain the same information but now use structured logging with key-value pairs instead of printf formatting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3ea5a29 commit d77b37b

3 files changed

Lines changed: 52 additions & 61 deletions

File tree

v3/pkg/application/application_darwin.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ static void startSingleInstanceListener(const char *uniqueID) {
197197
import "C"
198198
import (
199199
"encoding/json"
200-
"fmt"
201200
"unsafe"
202201

203202
"github.com/wailsapp/wails/v3/internal/operatingsystem"
@@ -384,34 +383,26 @@ func processDragItems(windowID C.uint, arr **C.char, length C.int, x C.int, y C.
384383
filenames = append(filenames, C.GoString(str))
385384
}
386385

387-
if globalApplication != nil && globalApplication.Logger != nil {
388-
globalApplication.Logger.Debug(
389-
"[DragDropDebug] processDragItems called",
390-
"windowID",
391-
windowID,
392-
"fileCount",
393-
len(filenames),
394-
"x",
395-
x,
396-
"y",
397-
y,
398-
)
399-
} else {
400-
fmt.Printf("[DragDropDebug] processDragItems called - windowID: %d, fileCount: %d, x: %d, y: %d\n", windowID, len(filenames), x, y)
401-
}
386+
globalApplication.debug(
387+
"[DragDropDebug] processDragItems called",
388+
"windowID",
389+
windowID,
390+
"fileCount",
391+
len(filenames),
392+
"x",
393+
x,
394+
"y",
395+
y,
396+
)
402397
targetWindow, ok := globalApplication.Window.GetByID(uint(windowID))
403398
if !ok || targetWindow == nil {
404399
println("Error: processDragItems could not find window with ID:", uint(windowID))
405400
return
406401
}
407402

408-
if globalApplication != nil && globalApplication.Logger != nil {
409-
globalApplication.Logger.Debug(
410-
"[DragDropDebug] processDragItems: Calling targetWindow.InitiateFrontendDropProcessing",
411-
)
412-
} else {
413-
fmt.Printf("[DragDropDebug] processDragItems: Calling targetWindow.InitiateFrontendDropProcessing\n")
414-
}
403+
globalApplication.debug(
404+
"[DragDropDebug] processDragItems: Calling targetWindow.InitiateFrontendDropProcessing",
405+
)
415406
targetWindow.InitiateFrontendDropProcessing(filenames, int(x), int(y))
416407
}
417408

v3/pkg/application/webview_window.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,35 +1221,35 @@ func (w *WebviewWindow) Error(message string, args ...any) {
12211221
}
12221222

12231223
func (w *WebviewWindow) HandleDragAndDropMessage(filenames []string, dropZone *DropZoneDetails) {
1224-
fmt.Printf(
1225-
"[DragDropDebug] HandleDragAndDropMessage called - Files: %v, DropZone: %+v\n",
1226-
filenames,
1227-
dropZone,
1224+
globalApplication.debug(
1225+
"[DragDropDebug] HandleDragAndDropMessage called",
1226+
"files", filenames,
1227+
"dropZone", dropZone,
12281228
)
12291229
thisEvent := NewWindowEvent()
1230-
fmt.Printf(
1231-
"[DragDropDebug] HandleDragAndDropMessage: thisEvent created, thisEvent.ctx is initially: %p\n",
1232-
thisEvent.ctx,
1230+
globalApplication.debug(
1231+
"[DragDropDebug] HandleDragAndDropMessage: thisEvent created",
1232+
"ctx", thisEvent.ctx,
12331233
)
12341234
ctx := newWindowEventContext()
12351235
ctx.setDroppedFiles(filenames)
12361236
if dropZone != nil { // Check if dropZone details are available
12371237
ctx.setDropZoneDetails(dropZone)
12381238
}
12391239
thisEvent.ctx = ctx
1240-
fmt.Printf(
1241-
"[DragDropDebug] HandleDragAndDropMessage: thisEvent.ctx assigned, thisEvent.ctx is now: %p, ctx is: %p\n",
1242-
thisEvent.ctx,
1243-
ctx,
1240+
globalApplication.debug(
1241+
"[DragDropDebug] HandleDragAndDropMessage: thisEvent.ctx assigned",
1242+
"thisEvent.ctx", thisEvent.ctx,
1243+
"ctx", ctx,
12441244
)
12451245
listeners := w.eventListeners[uint(events.Common.WindowDropZoneFilesDropped)]
1246-
fmt.Printf(
1247-
"[DragDropDebug] HandleDragAndDropMessage: Found %d listeners for WindowDropZoneFilesDropped\n",
1248-
len(listeners),
1246+
globalApplication.debug(
1247+
"[DragDropDebug] HandleDragAndDropMessage: Found listeners for WindowDropZoneFilesDropped",
1248+
"count", len(listeners),
12491249
)
1250-
fmt.Printf(
1251-
"[DragDropDebug] HandleDragAndDropMessage: Before calling listeners, thisEvent.ctx is: %p\n",
1252-
thisEvent.ctx,
1250+
globalApplication.debug(
1251+
"[DragDropDebug] HandleDragAndDropMessage: Before calling listeners",
1252+
"thisEvent.ctx", thisEvent.ctx,
12531253
)
12541254
for _, listener := range listeners {
12551255
if listener == nil {
@@ -1465,10 +1465,10 @@ func (w *WebviewWindow) ToggleMenuBar() {
14651465
}
14661466

14671467
func (w *WebviewWindow) InitiateFrontendDropProcessing(filenames []string, x int, y int) {
1468-
fmt.Printf(
1469-
"[DragDropDebug] InitiateFrontendDropProcessing called - X: %d, Y: %d",
1470-
x,
1471-
y,
1468+
globalApplication.debug(
1469+
"[DragDropDebug] InitiateFrontendDropProcessing called",
1470+
"x", x,
1471+
"y", y,
14721472
)
14731473
if w.impl == nil || w.isDestroyed() {
14741474
return

v3/pkg/application/webview_window_windows.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,20 @@ func (w *windowsWebviewWindow) convertWindowToWebviewCoordinates(windowX, window
560560
clientRect := w32.GetClientRect(w.hwnd)
561561
if clientRect == nil {
562562
// Fallback: return coordinates as-is if we can't get client rect
563-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Failed to get client rect, returning original coordinates (%d, %d)\n", windowX, windowY)
563+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Failed to get client rect, returning original coordinates", "windowX", windowX, "windowY", windowY)
564564
return windowX, windowY
565565
}
566566

567567
// Get the window rect to calculate the offset
568568
windowRect := w32.GetWindowRect(w.hwnd)
569569

570-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Input window coordinates: (%d, %d)\n", windowX, windowY)
571-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Window rect: Left=%d, Top=%d, Right=%d, Bottom=%d (Size: %dx%d)\n",
572-
windowRect.Left, windowRect.Top, windowRect.Right, windowRect.Bottom,
573-
windowRect.Right-windowRect.Left, windowRect.Bottom-windowRect.Top)
574-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Client rect: Left=%d, Top=%d, Right=%d, Bottom=%d (Size: %dx%d)\n",
575-
clientRect.Left, clientRect.Top, clientRect.Right, clientRect.Bottom,
576-
clientRect.Right-clientRect.Left, clientRect.Bottom-clientRect.Top)
570+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Input window coordinates", "windowX", windowX, "windowY", windowY)
571+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Window rect",
572+
"left", windowRect.Left, "top", windowRect.Top, "right", windowRect.Right, "bottom", windowRect.Bottom,
573+
"width", windowRect.Right-windowRect.Left, "height", windowRect.Bottom-windowRect.Top)
574+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Client rect",
575+
"left", clientRect.Left, "top", clientRect.Top, "right", clientRect.Right, "bottom", clientRect.Bottom,
576+
"width", clientRect.Right-clientRect.Left, "height", clientRect.Bottom-clientRect.Top)
577577

578578
// Convert client (0,0) to screen coordinates to find where the client area starts
579579
var point w32.POINT
@@ -589,20 +589,20 @@ func (w *windowsWebviewWindow) convertWindowToWebviewCoordinates(windowX, window
589589
windowOriginX := int(windowRect.Left)
590590
windowOriginY := int(windowRect.Top)
591591

592-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Client (0,0) in screen coordinates: (%d, %d)\n", clientX, clientY)
593-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Window origin in screen coordinates: (%d, %d)\n", windowOriginX, windowOriginY)
592+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Client (0,0) in screen coordinates", "clientX", clientX, "clientY", clientY)
593+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Window origin in screen coordinates", "windowOriginX", windowOriginX, "windowOriginY", windowOriginY)
594594

595595
// Calculate the offset from window origin to client origin
596596
offsetX := clientX - windowOriginX
597597
offsetY := clientY - windowOriginY
598598

599-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Calculated offset: (%d, %d)\n", offsetX, offsetY)
599+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Calculated offset", "offsetX", offsetX, "offsetY", offsetY)
600600

601601
// Convert window-relative coordinates to webview-relative coordinates
602602
webviewX := windowX - offsetX
603603
webviewY := windowY - offsetY
604604

605-
fmt.Printf("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates: (%d, %d)\n", webviewX, webviewY)
605+
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates", "webviewX", webviewX, "webviewY", webviewY)
606606

607607
return webviewX, webviewY
608608
}
@@ -1942,19 +1942,19 @@ func (w *windowsWebviewWindow) setupChromium() {
19421942
w.dropTarget = w32.NewDropTarget()
19431943
w.dropTarget.OnDrop = func(files []string, x int, y int) {
19441944
w.parent.emit(events.Windows.WindowDragDrop)
1945-
fmt.Printf("[DragDropDebug] Windows DropTarget OnDrop: Raw screen coordinates: (%d, %d)\n", x, y)
1945+
globalApplication.debug("[DragDropDebug] Windows DropTarget OnDrop: Raw screen coordinates", "x", x, "y", y)
19461946

19471947
// Convert screen coordinates to window-relative coordinates first
19481948
// Windows DropTarget gives us screen coordinates, but we need window-relative coordinates
19491949
windowRect := w32.GetWindowRect(w.hwnd)
19501950
windowRelativeX := x - int(windowRect.Left)
19511951
windowRelativeY := y - int(windowRect.Top)
19521952

1953-
fmt.Printf("[DragDropDebug] Windows DropTarget OnDrop: After screen-to-window conversion: (%d, %d)\n", windowRelativeX, windowRelativeY)
1953+
globalApplication.debug("[DragDropDebug] Windows DropTarget OnDrop: After screen-to-window conversion", "windowRelativeX", windowRelativeX, "windowRelativeY", windowRelativeY)
19541954

19551955
// Convert window-relative coordinates to webview-relative coordinates
19561956
webviewX, webviewY := w.convertWindowToWebviewCoordinates(windowRelativeX, windowRelativeY)
1957-
fmt.Printf("[DragDropDebug] Windows DropTarget OnDrop: Final webview coordinates: (%d, %d)\n", webviewX, webviewY)
1957+
globalApplication.debug("[DragDropDebug] Windows DropTarget OnDrop: Final webview coordinates", "webviewX", webviewX, "webviewY", webviewY)
19581958
w.parent.InitiateFrontendDropProcessing(files, webviewX, webviewY)
19591959
}
19601960
if opts.OnEnterEffect != 0 {
@@ -2293,13 +2293,13 @@ func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(
22932293
}
22942294
}
22952295

2296-
fmt.Printf("[DragDropDebug] processMessageWithAdditionalObjects: Raw WebView2 coordinates: (%d, %d)\n", x, y)
2296+
globalApplication.debug("[DragDropDebug] processMessageWithAdditionalObjects: Raw WebView2 coordinates", "x", x, "y", y)
22972297

22982298
// Convert webview-relative coordinates to window-relative coordinates, then to webview-relative coordinates
22992299
// Note: The coordinates from WebView2 are already webview-relative, but let's log them for debugging
23002300
webviewX, webviewY := x, y
23012301

2302-
fmt.Printf("[DragDropDebug] processMessageWithAdditionalObjects: Using coordinates as-is (already webview-relative): (%d, %d)\n", webviewX, webviewY)
2302+
globalApplication.debug("[DragDropDebug] processMessageWithAdditionalObjects: Using coordinates as-is (already webview-relative)", "webviewX", webviewX, "webviewY", webviewY)
23032303

23042304
w.parent.InitiateFrontendDropProcessing(filenames, webviewX, webviewY)
23052305
return

0 commit comments

Comments
 (0)