wails icon indicating copy to clipboard operation
wails copied to clipboard

[v2 - Linux] Fix backend drag and drop on Linux

Open makew0rld opened this issue 1 year ago • 10 comments

Description

This PR fixes #3686 by copying a dead PR, #3704.

Type of change

Please select the option that is relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • [x] Windows: works
  • [x] macOS: works
  • [x] Linux: works

If you checked Linux, please specify the distro and version: Arch Linux latest

Test Configuration

# Wails
Version         | v2.9.2
Package Manager | pacman

# System
┌───────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Arch Linux                                                             |
| Version      | Unknown                                                                |
| ID           | arch                                                                   |
| Go Version   | go1.23.3                                                               |
| Platform     | linux                                                                  |
| Architecture | amd64                                                                  |
| CPU          | 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz                         |
| GPU          | TigerLake-LP GT2 [Iris Xe Graphics] (Intel Corporation) - Driver: i915 |
| Memory       | 15GB                                                                   |
└───────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌─────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version                     |
| *docker    | docker       | Installed | 1:27.3.1-1                  |
| gcc        | gcc          | Installed | 14.2.1+r134+gab884fffe3fc-1 |
| libgtk-3   | gtk3         | Installed | 1:3.24.43-4                 |
| libwebkit  | webkit2gtk   | Installed | 2.46.4-1                    |
| npm        | npm          | Installed | 10.9.0-1                    |
| pkg-config | pkgconf      | Installed | 2.1.1-1                     |
└────────────────────── * - Optional Dependency ──────────────────────┘

# Diagnosis
 SUCCESS  Your system is ready for Wails development!

Checklist:

  • [ ] I have updated website/src/pages/changelog.mdx with details of this PR
  • [ ] My code follows the general coding style of this project
  • [ ] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] New and existing unit tests pass locally with my changes

I don't fully understand this PR (hopefully you do instead) but the basic reason why it works is because it registers event listeners that call e.PreventDefault() so the default file drop behaviour is stopped.

This requires doc updates because callers need to know that backend file drop handlers should be registered in OnDomReady, not OnStartup.

Summary by CodeRabbit

  • New Features

    • Enhanced drag-and-drop functionality with improved event listener management.
    • Added support for file drop events, ensuring listeners are registered only once during initialization.
  • Bug Fixes

    • Improved handling of drag-and-drop operations to ensure callbacks are invoked only on valid drop targets.

makew0rld avatar Dec 14 '24 01:12 makew0rld

Walkthrough

The changes in this pull request focus on enhancing the drag-and-drop functionality within the application. Key modifications include the introduction of an EventsOnce listener that initializes drag-and-drop event handlers when the "wails:init-file-drop" event is triggered. This ensures that event listeners are registered only once, improving efficiency. Additionally, the OnFileDrop function has been updated to emit an event at the start of the file drop process while maintaining its original logic.

Changes

File Path Change Summary
v2/internal/frontend/runtime/desktop/draganddrop.js Added EventsOnce import and listener for "wails:init-file-drop" to manage drag-and-drop events.
v2/internal/frontend/runtime/runtime_debug_desktop.js Introduced EventsOnce listener for drag-and-drop initialization based on the enableWailsDragAndDrop flag.
v2/pkg/runtime/draganddrop.go Modified OnFileDrop to emit "wails:init-file-drop" event at the start of the drop process.

Assessment against linked issues

Objective Addressed Explanation
Ensure file view does not appear when dropping files (3686)

Possibly related PRs

  • #3742: Addresses a bug related to drag-and-drop functionality, relevant to the enhancements made in this PR.
  • #3856: Introduces a test for the HTML Drag and Drop API, aligning with the focus on improving drag-and-drop functionality.
  • #3886: Includes fixes for drag-and-drop functionality, making it relevant to the changes in this PR.
  • #3907: Discusses improvements to systray click handling, which may relate to drag-and-drop interactions.
  • #3925: Addresses a bug in the Linux dialog for multiple selections, potentially involving drag-and-drop operations.

Suggested reviewers

  • atterpac

🐰 In the land of code where rabbits play,
Drag-and-drop now works in a better way!
Events registered just once, oh so neat,
Our UI stays intact, a real treat!
With each file dropped, a new event sings,
Hopping along, we embrace these changes! 🐇✨

[!TIP] CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Dec 14 '24 01:12 coderabbitai[bot]

@atterpac - any thoughts on this?

leaanthony avatar Dec 20 '24 06:12 leaanthony

Any chance this could be merged soon? Thanks.

makew0rld avatar Jan 05 '25 17:01 makew0rld

Ok I am seeing one issue with this PR so far, which is that it doesn't seem to work properly with a built binary (wails build) even though wails dev works fine.

  • Linux binary: reverts back to original behaviour described in #3686
  • ~~macOS binary: the file drop is not detected, no green plus shows up on hover/drag~~

I don't get why this would happen. Maybe related to #3563?

It would be good if someone else could confirm this.

makew0rld avatar Jan 05 '25 18:01 makew0rld

I can try to look at this this week at some point. Perhaps @atterpac could look at it if he has time.

leaanthony avatar Jan 05 '25 22:01 leaanthony

I can try to look at this this week at some point. Perhaps @atterpac could look at it if he has time.

I can look into it

atterpac avatar Jan 05 '25 22:01 atterpac

This looks gtg to me @leaanthony

atterpac avatar Feb 12 '25 12:02 atterpac

Thanks @makew0rld 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx? Could you also please revert the changes to the debug runtime file? We'll need to generate both debug and prod versions, which I'm happy to do 👍

leaanthony avatar Feb 13 '25 20:02 leaanthony

I actually I am not very confident in this PR, I think it may be an incomplete solution. See my comment above, and also this comment which explains what I currently do in my actual application.

I would need to do more testing before I consider it ready to merge. I don't have a lot of time for it at the moment but I'll see what I can do.

makew0rld avatar Feb 13 '25 21:02 makew0rld

Fair enough. Converted to draft 👍

leaanthony avatar Feb 13 '25 21:02 leaanthony

@makew0rld - I'm assuming this is abandoned now? Please reopen if not 🙏

leaanthony avatar Aug 02 '25 04:08 leaanthony