feat: expose raw drag text in DropDoneDetails for portal integration - #492
feat: expose raw drag text in DropDoneDetails for portal integration#492loucass wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Exposes Linux drag payloads through DropDoneEvent and widget callbacks for portal integrations.
Changes:
- Adds optional
rawTextfields and Linux propagation. - Exports raw drop events publicly.
- Adds Linux tests and a 0.8.1 changelog entry.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
packages/desktop_drop/lib/src/events.dart |
Adds raw payload data to drop events. |
packages/desktop_drop/lib/src/drop_target.dart |
Passes raw payloads to widget callbacks. |
packages/desktop_drop/lib/src/channel.dart |
Attaches Linux channel text to events. |
packages/desktop_drop/lib/desktop_drop.dart |
Exports event types publicly. |
packages/desktop_drop/test/channel_linux_test.dart |
Tests Linux payload parsing and preservation. |
packages/desktop_drop/CHANGELOG.md |
Documents version 0.8.1. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| _notifyEvent(DropDoneEvent( | ||
| location: Offset(offset[0], offset[1]), | ||
| files: paths.map((e) => DropItemFile(e)).toList(), | ||
| rawText: text, |
There was a problem hiding this comment.
One GTK 3 detail changes the diagnosis here: since GTK 3.24.37, gtk_drag_dest_add_uri_targets() already adds both application/vnd.portal.filetransfer and the legacy application/vnd.portal.files when the FileTransfer portal is available. Therefore the portal payload can reach this callback on current GTK without another explicit target entry.
There is still a negotiation problem worth addressing. gtk_drag_dest_find_target() selects the first destination target also offered by the source, while this plugin registers STRING first and gtk_target_list_add_uri_targets() appends text/uri-list before the portal targets. If a source offers both URI and portal representations, the inaccessible URI representation may still win. The native layer should prefer the portal target and pass the selected MIME type alongside its payload so Dart does not infer the type from the text.
The tests should also use the payloads GTK can actually deliver: either a URI list or a key-only portal payload. A combined file://...\nportal-key payload is not produced by MIME negotiation.
| /// The portal key line is NOT a file URI and can be distinguished | ||
| /// by not starting with `file://`. It is only present when the | ||
| /// drag source used the XDG Desktop Portal (typical for sandboxed | ||
| /// apps on Wayland). |
| /// The portal key line is NOT a file URI and can be distinguished | ||
| /// by not starting with `file://`. It is only present when the | ||
| /// drag source used the XDG Desktop Portal (typical for sandboxed | ||
| /// apps on Wayland). |
| @@ -1,5 +1,9 @@ | |||
| # Changelog | |||
|
|
|||
| ## 0.8.1 | |||
| @override | ||
| String toString() { | ||
| return '$runtimeType($location, $files)'; | ||
| return '$runtimeType($location, $files, rawText: $rawText)'; |
Problem
Flutter apps running in Flatpak sandboxes on Wayland cannot receive files dragged from outside their permitted directories (e.g.,
~/Documents/). The XDG Desktop PortalFileTransfermechanism mediates this: the source app registers the file and passes a key via theapplication/vnd.portal.filetransfermimetype. The target app must callRetrieveFiles(key)to get a sandbox-accessible path.Currently,
desktop_droponly exposes parsedfile://URIs viaDropDoneDetails.files. The raw drag text containing the portal key is discarded.Solution
Expose the raw drag text received from GTK through the event chain:
DropDoneEvent.rawText— optional field carrying the original drag dataDropDoneDetails.rawText— passed through to the widget callbackevents.dartso consumers can accessDropDoneEventDropDoneEventChanges
packages/desktop_drop/lib/src/events.dart: AddrawTexttoDropDoneEventwith documentationpackages/desktop_drop/lib/src/drop_target.dart: AddrawTexttoDropDoneDetails, populate from event, with documentationpackages/desktop_drop/lib/src/channel.dart: PassrawText: textin LinuxperformOperation_linuxcasepackages/desktop_drop/lib/desktop_drop.dart: Exportevents.dartpackages/desktop_drop/CHANGELOG.md: Version 0.8.1 entryCross-Platform Behavior
rawTextValuenull(structured data only)null(paths list only)null(structured data only)Optional field, only populated where platform provides it.
Testing
~/Downloads/→ works (existing permission)~/Documents/→ now works via portal (key retrieved,RetrieveFilesreturns accessible path)rawTextis optional, defaults tonullFollow-up
This enables LocalSend (and other Flatpak Flutter apps) to implement proper portal-based drag-and-drop. Separate PR to LocalSend will consume this API.