Skip to content

feat: expose raw drag text in DropDoneDetails for portal integration - #492

Open
loucass wants to merge 2 commits into
MixinNetwork:mainfrom
loucass:feat/raw-text-drop-details
Open

feat: expose raw drag text in DropDoneDetails for portal integration#492
loucass wants to merge 2 commits into
MixinNetwork:mainfrom
loucass:feat/raw-text-drop-details

Conversation

@loucass

@loucass loucass commented Aug 23, 2026

Copy link
Copy Markdown

Problem

Flutter apps running in Flatpak sandboxes on Wayland cannot receive files dragged from outside their permitted directories (e.g., ~/Documents/). The XDG Desktop Portal FileTransfer mechanism mediates this: the source app registers the file and passes a key via the application/vnd.portal.filetransfer mimetype. The target app must call RetrieveFiles(key) to get a sandbox-accessible path.

Currently, desktop_drop only exposes parsed file:// URIs via DropDoneDetails.files. The raw drag text containing the portal key is discarded.

Solution

Expose the raw drag text received from GTK through the event chain:

  1. DropDoneEvent.rawText — optional field carrying the original drag data
  2. DropDoneDetails.rawText — passed through to the widget callback
  3. Export events.dart so consumers can access DropDoneEvent
  4. Linux channel now passes raw text to DropDoneEvent

Changes

  • packages/desktop_drop/lib/src/events.dart: Add rawText to DropDoneEvent with documentation
  • packages/desktop_drop/lib/src/drop_target.dart: Add rawText to DropDoneDetails, populate from event, with documentation
  • packages/desktop_drop/lib/src/channel.dart: Pass rawText: text in Linux performOperation_linux case
  • packages/desktop_drop/lib/desktop_drop.dart: Export events.dart
  • packages/desktop_drop/CHANGELOG.md: Version 0.8.1 entry

Cross-Platform Behavior

Platform rawText Value
Linux/Wayland Full GTK drag text (file:// URIs + portal keys)
macOS null (structured data only)
Windows null (paths list only)
Web null (structured data only)

Optional field, only populated where platform provides it.

Testing

  • Verified with LocalSend Flatpak on Fedora KDE Wayland (Plasma 6.7.4)
  • Drag from ~/Downloads/ → works (existing permission)
  • Drag from ~/Documents/ → now works via portal (key retrieved, RetrieveFiles returns accessible path)
  • Backward compatible — rawText is optional, defaults to null
  • No behavior change for non-portal drag sources

Follow-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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes Linux drag payloads through DropDoneEvent and widget callbacks for portal integrations.

Changes:

  • Adds optional rawText fields 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +47 to +50
/// 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).
Comment on lines +38 to +41
/// 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)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants