wails/v3/examples
Lea Anthony 53c2275fea
fix(v3): overhaul drag-and-drop for Linux reliability and simplify Windows implementation (#4848)
* fix(v3): overhaul drag-and-drop for Linux reliability and simplify Windows

This commit fixes drag-and-drop reliability on Linux and simplifies the
Windows implementation.

## Linux
- Rewrite GTK drag handlers to properly intercept external file drops
- Fix HTML5 internal drag-and-drop being broken when file drop enabled
- Add hover effects during file drag operations
- Fix multiple app instances interfering with each other

## Windows
- Remove native IDropTarget in favor of JavaScript approach (matches v2)
- File drops now handled via chrome.webview.postMessageWithAdditionalObjects

## All Platforms
- Rename EnableDragAndDrop to EnableFileDrop
- Rename data-wails-drop-target to data-file-drop-target
- Rename wails-drop-target-active to file-drop-target-active
- Add comprehensive drag-and-drop documentation

## Breaking Changes
- EnableDragAndDrop -> EnableFileDrop
- data-wails-dropzone -> data-file-drop-target
- wails-dropzone-hover -> file-drop-target-active
- DropZoneDetails -> DropTargetDetails
- Remove WindowDropZoneFilesDropped event (use WindowFilesDropped)

* feat(macos): optimize drag event performance with debouncing and caching

- Add 50ms debouncing to limit drag events to 20/sec (was 120/sec)
- Implement window implementation caching to avoid repeated lookups
- Maintain existing 5-pixel threshold for immediate response
- Keep zero-allocation path with pre-allocated buffers
- Rename linuxDragActive to nativeDragActive for clarity
- Update IMPLEMENTATION.md with optimization details and Windows guidance

Performance improvements:
- 83% reduction in event frequency
- ~6x reduction in CPU/memory usage during drag operations
- Maintains smooth visual feedback with InvokeSync for timer callbacks

* fix(windows): implement proper file drop support for Windows

- Remove incorrect AllowExternalDrag(false) call that was blocking file drops
- Fix message prefix from 'FilesDropped' to 'file:drop:' to match JS runtime
- Fix coordinate parsing for 'file:drop:x:y' format (indices 2,3 not 1,2)
- Add enableFileDrop flag injection to JS runtime during navigation
- Update JS runtime to check enableFileDrop flag before processing drops
- Always call preventDefault() to stop browser navigation on file drags
- Show 'no drop' cursor when file drops are disabled
- Update example to filter file drags from HTML drop zone handlers
- Add documentation for combining file drop with HTML drag-and-drop

* fix(v3): block file drops on Linux when EnableFileDrop is false

- Add disableDND() to intercept and reject external file drags at GTK level
- Show 'no drop' cursor when files are dragged over window
- Allow internal HTML5 drag-and-drop to work normally
- Initialize _wails.flags object in runtime core to prevent undefined errors
- Inject enableFileDrop flag on Linux and macOS (matching Windows)
- Fix bare _wails reference to use window._wails
- Update docs with info about blocked drops and combining with HTML DnD

* fix(darwin): add missing fmt import in webview_window_darwin.go

* fix(macOS): implement hover effects for file drag-and-drop with optimizations

- Added draggingUpdated: handler to track mouse movement during drag operations
- Implemented macosOnDragEnter/Exit/Over export functions for real-time hover state
- Fixed JS function call from '_wails.handlePlatformFileDrop' to correct 'wails.Window.HandlePlatformFileDrop'
- Added EnableFileDrop flag checks to prevent hover effects when file drops are disabled
- Renamed linuxDragActive to nativeDragActive for cross-platform consistency

Performance optimizations:
- Added 50ms debounce to reduce event frequency from ~120/sec to ~20/sec
- Implemented 5-pixel movement threshold for immediate response
- Added window caching with sync.Map to avoid repeated lookups
- Zero-allocation JavaScript calls with pre-allocated 128-byte buffer
- Reduced memory usage to ~18 bytes per event (6x reduction)

Build improvements:
- Updated runtime Taskfile to include documentation generation
- Added docs:build task to runtime build process
- Fixed build order: events → docs → runtime

Documentation:
- Added IMPLEMENTATION.md with optimization details
- Included guidance for Windows implementation

* chore(v3/examples): remove html-dnd-api example

The drag-n-drop example now demonstrates both external file drops
and internal HTML5 drag-and-drop, making this separate example redundant.

* docs(v3): move drag-and-drop implementation details to runtime-internals

- Add drag-and-drop section to contributing/runtime-internals.mdx
- Remove IMPLEMENTATION.md from example (content now in proper docs)
- Covers platform differences, debugging tips, and key files

* fix(v3): remove html-dnd-api from example build list

* fix(v3): remove duplicate json import in application_darwin.go

* fix(v3): address CodeRabbit review feedback

- Fix docs to use app.Window.NewWithOptions() instead of deprecated API
- Add mutex protection to dragOverJSBuffer to prevent race conditions
- Add mutex protection to dragThrottleState fields for thread safety

* docs: add coderabbit pre-push requirement to AGENTS.md

* fix(v3/test): use correct CSS class name file-drop-target-active

* chore(v3/test): remove dnd-test directory

This was a development test file that shouldn't be in the PR.
The drag-n-drop example serves as the proper test case.

* docs(v3): update Windows file drop comment to reflect implemented fix

Remove stale TODO - enableFileDrop flag is now injected in navigationCompleted

* refactor(v3): make handleDragAndDropMessage unexported

Internal method only called by application event loop, not part of public API.
2026-01-04 11:08:29 +11:00
..
android feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
badge [v3] Typed Events, revisited (#4633) 2025-11-11 20:25:57 +11:00
badge-custom [v3] Typed Events, revisited (#4633) 2025-11-11 20:25:57 +11:00
binding Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
build docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
cancel-async Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
cancel-chaining Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
clipboard docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
contextmenus Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
custom-protocol-example [v3] Typed Events, revisited (#4633) 2025-11-11 20:25:57 +11:00
dev feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
dialogs docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
dialogs-basic docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
dock [v3] macOS Dock Service (#4451) 2025-09-24 07:30:02 +00:00
drag-n-drop fix(v3): overhaul drag-and-drop for Linux reliability and simplify Windows implementation (#4848) 2026-01-04 11:08:29 +11:00
environment Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
events Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
events-bug docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
file-association docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
frameless window.ToggleFrameless() api (#4317) 2025-07-15 22:53:21 +10:00
gin-example feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
gin-routing feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
gin-service feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
hide-window Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
ignore-mouse Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
ios feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
ios-poc Merge iOS support from v3-alpha-feature/ios-support 2025-12-10 18:34:21 +11:00
keybindings Refactor to using Window interface (#4471) 2025-08-09 15:28:08 +10:00
liquid-glass fix(v3): overhaul drag-and-drop for Linux reliability and simplify Windows implementation (#4848) 2026-01-04 11:08:29 +11:00
menu [V3 Alpha] Improves macOS Window menu support (#4588) 2025-09-25 13:30:59 +10:00
notifications feat(linux): generate .desktop file during build (#4575) (#4780) 2025-12-13 12:22:59 +11:00
panic-handling docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
plain Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
print fix(macos): fix print dialog not opening and add Window.Print() to runtime (#4789) 2025-12-14 15:04:54 +11:00
raw-message [V3] Add origin to raw message handler (#4710) 2025-12-08 20:29:09 +11:00
screen Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
services Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
show-macos-toolbar Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
single-instance Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
spotlight feat(macos): add CollectionBehavior option to MacWindow (#4799) 2025-12-29 11:07:37 +11:00
systray-basic Refactor to using Window interface (#4471) 2025-08-09 15:28:08 +10:00
systray-clock [v3 alpha] windows tray minor refactor (#4653) 2025-11-04 07:44:58 +11:00
systray-custom Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
systray-menu docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
video Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
websocket-transport [V3] Refactor binding transport layer (#4702) 2025-12-07 22:19:12 +11:00
window docs: Update dialogs documentation to match actual v3 API (#4793) 2025-12-16 06:05:40 +11:00
window-api Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
window-call Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
window-menu Refactor to using Window interface (#4471) 2025-08-09 15:28:08 +10:00
wml Refactor Manager API to use singular naming convention (#4367) 2025-06-22 12:19:14 +10:00
linux_status.org add linux status for examples 2023-11-06 10:49:14 -06:00
README.md Improve documentation 2023-12-13 22:40:35 +11:00

v3

NOTE: The examples in this directory may or may not compile / run at any given time during alpha development.

Running the examples

cd v3/examples/<example>
go mod tidy
go run .

Compiling the examples

cd v3/examples/<example>
go mod tidy
go build
./<example>