tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.63k stars 2.51k forks source link

[bug] `TauriEvent.DRAG_DROP` don't fire on Arch Linux with Wayland #11282

Open Jisu-Woniu opened 1 week ago

Jisu-Woniu commented 1 week ago

Describe the bug

When dragging files to Tauri apps on Arch Linux, the Tauri app can fire DRAG_ENTER, DRAG_OVER and DRAG_LEAVE events, but not DRAG_DROP.

Reproduction

  1. On Arch Linux, create a Tauri + Vue.js app with pnpm create tauri-app
  2. Follow the instructions to install the dependencies
  3. Replace the src/App.vue file with:

    <script setup lang="ts">
    import {
      listen,
      TauriEvent,
      type Event,
      type UnlistenFn,
    } from "@tauri-apps/api/event";
    import { onMounted, onUnmounted } from "vue";
    let unlistenFns: UnlistenFn[] = [];
    
    onMounted(async () => {
      const logEvent = (e: Event<unknown>) => {
        console.log(e.event, e.payload);
      };
      unlistenFns = await Promise.all([
        listen(TauriEvent.DRAG_ENTER, logEvent),
        // DRAG_OVER works but produces a lot of events, so we don't log them
        // listen(TauriEvent.DRAG_OVER, logEvent),
        listen(TauriEvent.DRAG_LEAVE, logEvent),
        listen(TauriEvent.DRAG_DROP, logEvent),
      ]);
    });
    onUnmounted(() => {
      for (const unlistenFn of unlistenFns) {
        unlistenFn();
      }
      // clear the array
      unlistenFns.length = 0;
    });
    </script>
    
    <template>
      <h1>Drag some files here</h1>
    </template>
  4. Run the app with pnpm tauri dev.
  5. Press Ctrl + Shift + I to open the DevTools window.
  6. Drag files to the app window and drop them.

Expected behavior

The app should produce one tauri://drag-enter event and one tauri://drag-drop event for each file.

But no tauri://drag-drop event is fired on my side.

Screenshot of logs

I have also checked with CrabNebula DevTools, only tauri://drag-enter, tauri://drag-over and tauri://drag-leave are fired.

Full tauri info output

> tauri-app@0.1.0 tauri **PROJ_DIR**
> tauri "info"

[✔] Environment
    - OS: Arch Linux Rolling Release x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.46.1
    ✔ rsvg2: 2.59.1
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (2024-05-07)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 20.18.0
    - pnpm: 9.12.1
    - npm: 10.9.0
    - bun: 1.1.30

[-] Packages
    - tauri 🦀: 2.0.2
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.2
    - @tauri-apps/cli : 2.0.2

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.1
    - @tauri-apps/plugin-shell : 2.0.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

Jisu-Woniu commented 1 week ago

In case it is needed, I used KDE Plasma 6.1.5 (Wayland) on my machine.

JuTonic commented 6 days ago

Can confirm an issue is present and seems to be a Wayland problem. On Xorg drop event fires correctly.

To say more on the problem, in my case on Wayland when using the newest v2 version of a tauri there is just no way to get a filepath of a file being dragged (it is not accessible neither in drag-over, nor in drag-leave). I tried everything. On v2-beta version I can get a filepath through a drag-over event (I tested it with https://github.com/xingrz/tauri-v2-drag-n-drop), but drop event does not fire here too.

On xorg another bug appears - images of dragged files does not disappear when dropped and stays on the screen (look at the image below). Though, It might be my setup (Artix linux, GNOME 47)

image

In case info is needed

[✔] Environment
    - OS: Artix Linux Unknown x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.46.1
    ✔ rsvg2: 2.59.1
    ✔ rustc: 1.83.0-nightly (14f303bc1 2024-10-04)
    ✔ cargo: 1.83.0-nightly (80d82ca22 2024-09-27)
    ✔ rustup: 1.27.1 (2024-05-07)
    ✔ Rust toolchain: nightly-x86_64-unknown-linux-gnu (default)
    - node: 22.9.0
    - pnpm: 9.6.0
    - yarn: 1.22.22
    - npm: 10.9.0
    - bun: 1.1.27

[-] Packages
    - tauri 🦀: 2.0.1
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.2
    - @tauri-apps/cli : 2.0.2

[-] Plugins
    - tauri-plugin-fs 🦀: 2.0.1
    - @tauri-apps/plugin-fs : 2.0.0
    - tauri-plugin-shell 🦀: 2.0.1
    - @tauri-apps/plugin-shell : 2.0.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite
metdxt commented 3 days ago

Having the same problem on Ubuntu 24.04. However it appears I'm running Xorg session:

$ echo $XDG_SESSION_TYPE
x11

Drag and drop events work for me, but icons get stuck like JuTonic mentioned

tauri info ```console $ npm run tauri info > coref@0.1.0 tauri > tauri info [✔] Environment - OS: Ubuntu 24.4.0 x86_64 (X64) ✔ webkit2gtk-4.1: 2.44.3 ✔ rsvg2: 2.58.0 ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04) ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20) ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24) ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default) - node: 20.17.0 - npm: 10.8.2 [-] Packages - tauri 🦀: 2.0.2 - tauri-build 🦀: 2.0.1 - wry 🦀: 0.44.1 - tao 🦀: 0.30.3 - @tauri-apps/api : 2.0.2 - @tauri-apps/cli : 2.0.2 (outdated, latest: 2.0.3) [-] Plugins - tauri-plugin-shell 🦀: 2.0.1 - @tauri-apps/plugin-shell : 2.0.0 [-] App - build-type: bundle - CSP: unset - frontendDist: ../build - devUrl: http://localhost:1420/ - framework: Svelte - bundler: Vite ```
Source code (Only what's changed from original svelte template) ```svelte // src/routes/+page.svelte

Files dropped:

    {#each all_paths as path}
  • {path}
  • {/each}
``` ```rust // src-tauri/src/main.rs // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use std::env; fn main() { unsafe { // To prevent UI not showing up, see https://github.com/tauri-apps/tauri/issues/10626#issuecomment-2289478824 env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1"); } coref_lib::run() } ```
Jisu-Woniu commented 3 days ago

I think the "icons get stuck" problem should be mentioned in a separate issue. @JuTonic @metdxt

JuTonic commented 3 days ago

I think the "icons get stuck" problem should be mentioned in a separate issue. @JuTonic @metdxt

I agree, especially now when I know it is not a problem of my setup. Gonna open a new issue

metdxt commented 3 days ago

UPD: After updating to Ubuntu 24.10, which has wayland, Tauri drop events are not working, instead default browser handlers work, which I assume is unintended. After dropping the file into the window browser just opens it. To void that one gotta make preventDefault:

<script lang="ts">
    import { onMount, onDestroy } from "svelte";
    import { listen, TauriEvent } from "@tauri-apps/api/event";
    import type { UnlistenFn } from "@tauri-apps/api/event";

    let all_paths: string[] = [];

    interface DnDResult {
        paths: string[];
        position: { x: number; y: number };
    }

    let unlisten: UnlistenFn;

    function preventSilent(event: DragEvent) {
        event.preventDefault()
    }
    function preventLog(event: DragEvent) {
        console.log(event);
        event.preventDefault();
    }

    onMount(async () => {
        // Both of these are needed.
        window.addEventListener('dragover', preventSilent);
        window.addEventListener('drop', preventLog);

        unlisten = await listen(TauriEvent.DRAG_DROP, (event) => {
            let { paths, position } = event.payload as DnDResult;
            console.log("Files dropped:", paths);
            all_paths = paths;
        });

        console.log("DnD handler registered");
    });

    onDestroy(() => {
        if (unlisten) {
            unlisten();
        }
    });
</script>

<div>
    <h1>Files dropped:</h1>
    <ul>
        {#each all_paths as path}
        <li>{path}</li>
        {/each}
    </ul>
</div>

However it doesn't change anything about tauri drop events not working.

tauri info just in case ``` > coref@0.1.0 tauri > tauri info [✔] Environment - OS: Ubuntu 24.10.0 x86_64 (X64) ✔ webkit2gtk-4.1: 2.46.1 ✔ rsvg2: 2.59.1 ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04) ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20) ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24) ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default) - node: 20.17.0 - npm: 10.8.2 [-] Packages - tauri 🦀: 2.0.2 - tauri-build 🦀: 2.0.1 - wry 🦀: 0.44.1 - tao 🦀: 0.30.3 - @tauri-apps/api : 2.0.2 - @tauri-apps/cli : 2.0.2 (outdated, latest: 2.0.3) [-] Plugins - tauri-plugin-shell 🦀: 2.0.1 - @tauri-apps/plugin-shell : 2.0.0 [-] App - build-type: bundle - CSP: unset - frontendDist: ../build - devUrl: http://localhost:1420/ - framework: Svelte - bundler: Vite ```
Jisu-Woniu commented 1 day ago

I noticed that if I drag something the browser can open, e.g. SVG or JSON files, the WebView will open the file. I think it is the case, I will try to confirm that.

EDIT: Tried that, but the JSON file still opened in the WebView on my side.