Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping files (ondrop) doesn't work on Windows #2954

Closed
Boscop opened this issue Sep 12, 2024 · 12 comments · Fixed by #3046
Closed

Dropping files (ondrop) doesn't work on Windows #2954

Boscop opened this issue Sep 12, 2024 · 12 comments · Fixed by #3046
Labels
bug Something isn't working windows

Comments

@Boscop
Copy link

Boscop commented Sep 12, 2024

Problem

Dropping files (ondrop) doesn't work on Windows, the even doesn't seem to get triggered.

Steps To Reproduce

Steps to reproduce the behavior:

  • cargo r --example file_upload
  • Click on "Choose Files" (the file input) and select a .txt file -> That works fine but:
  • Now click "Clear Files" and drag the same .txt file from Windows Explorer and drop it onto the "Drop files here" area
  • Nothing happens!

Expected behavior

It should load the file just like when opening it by clicking on the file input and selecting it through the file dialog.

Screenshots

image

Environment:

  • Dioxus version: latest main branch, commit b20db13e84227b76741e007b2763adc8237ada48
  • Rust version: rustc 1.82.0-nightly (8b3870784 2024-08-07)
  • OS info: Windows 11
  • App platform: desktop
@matthunz matthunz added bug Something isn't working windows labels Sep 12, 2024
@matthunz
Copy link
Contributor

matthunz commented Sep 12, 2024

Thanks for reporting this!

Looks like it is working on MacOS (and no open issues I can see for tao)

Screenshot 2024-09-12 at 6 44 19 PM

@Boscop
Copy link
Author

Boscop commented Sep 14, 2024

@matthunz Yeah, IIRC I reported an issue with file dropping on Windows when the Tauri project was in early stages, not sure on which repo though, I couldn't find the issue or if it was solved..

EDIT: I think it was this, but it's a different problem: tauri-apps/tao#62

@DogeDark
Copy link
Member

I can verify that this does not work on Windows 10, Dioxus main.

@Boscop
Copy link
Author

Boscop commented Oct 3, 2024

@DogeDark Do you think it's a tao issue?

@DogeDark
Copy link
Member

DogeDark commented Oct 4, 2024

@Boscop I'm unsure. I only tested to verify the issue.

@Boscop
Copy link
Author

Boscop commented Oct 4, 2024

Apparently it's not a tao/wry issue: tauri-apps/tao#986 (comment)

The tao drag and drop events work just fine on Windows, you can run cargo run --example window and drag a file onto the window, and the event will be logged.
I think dioxus is using wry as well, and in that case you might be looking for docs.rs/wry/latest/wry/struct.WebViewBuilder.html#method.with_drag_drop_handler

So it must be a dioxus issue then..

@DogeDark
Copy link
Member

DogeDark commented Oct 4, 2024

I did some digging and it seems like with_drag_drop_handler blocks the HTML ondrag, ondrop and ondragover events on Windows. If we remove it, our event handlers get called correctly but we rely on with_drag_drop_handler for the file so the app panics. It looks like with_drag_drop_handler has different behavior depending on the platform (or system webview?) since it worked on MacOS.

@Boscop
Copy link
Author

Boscop commented Oct 5, 2024

@DogeDark Hm, what do you mean by "If we remove it, our event handlers get called correctly but we rely on with_drag_drop_handler for the file so the app panics."?

Shouldn't the HTML drag/drop events be working in conjunction with / backed by with_drag_drop_handler?

@DogeDark
Copy link
Member

DogeDark commented Oct 5, 2024

@Boscop We have a JavaScript shim that is called by Dioxus to create event listeners and when with_drag_drop_handler is used, the JS-native event listeners I mentioned aren't called at all when with_drag_drop_handler is used. The with_drag_drop_handler only sets the latest file(s) that were hovered over the application. Our Rust code that handles the file drop event expects the with_drag_drop_handler to have set a value but it hasn't so it panics.

@Boscop
Copy link
Author

Boscop commented Oct 7, 2024

@DogeDark

The with_drag_drop_handler only sets the latest file(s) that were hovered over the application.

I found that here

let file_drop_handler = {

And about this:

Our Rust code that handles the file drop event expects the with_drag_drop_handler to have set a value but it hasn't

Why doesn't it set the value? :)

@DogeDark
Copy link
Member

DogeDark commented Oct 7, 2024

@Boscop It does, it's just with the drop handler, the HTML events don't get called. Without the drop handler, the HTML events work fine except panics because the drop handler was expected to have set the most recent file:

let file_event = recent_file.current().unwrap();

Most likely related: tauri-apps/wry#904

I'm looking into creating a solution.

@Boscop
Copy link
Author

Boscop commented Oct 9, 2024

Ah..
Thanks for looking into a solution for this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants