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

[dialog][v2][linux] Any blocking dialog does not display properly when running on Linux #956

Closed
watiko opened this issue Feb 15, 2024 · 5 comments · Fixed by #1033
Closed
Labels
bug Something isn't working

Comments

@watiko
Copy link

watiko commented Feb 15, 2024

description

The code example below is from the Rust side, but it hangs the same way from the frontend because the blocking dialog is invoked via Command. However, this seems to be a problem that invoke_with_priority may not be able to aquire MainContext, so it may work in some cases.

Note: I think tauri v1 also has the same problem.

  • ref:
    #[cfg(target_os = "linux")]
    macro_rules! run_dialog {
    ($e:expr, $h: ident) => {{
    std::thread::spawn(move || {
    let context = glib::MainContext::default();
    context.invoke_with_priority(glib::PRIORITY_HIGH, move || $h($e));
    });
    }};
    }

What I did

$ npm create tauri-app@latest -- --alpha
warning: The `--alpha` option is now an alias for `--beta` and may be removed in the future.
✔ Project name · tauri-v2-exp2
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
✔ Choose your package manager · npm
✔ Choose your UI template · React - (https://react.dev/)
✔ Choose your UI flavor · TypeScript
✔ Would you like to setup the project for mobile as well? · no

Template created! To get started run:
  cd tauri-v2-exp2
  npm install
  npm run tauri dev

$ cd tauri-v2-exp2
$ npm i
$ npm run tauri add dialog
$ vim src-tauri/src/main.rs
$ npm run tauri dev
// src-tauri/src/main.rs
use tauri_plugin_dialog::DialogExt;

#[tauri::command]
fn greet<R: tauri::Runtime>(app: tauri::AppHandle<R>, name: &str) -> String {
    // The dialog does not appear and this program is stuck on next line.
    app.dialog().message("hello").blocking_show();

    format!("Hello, {}! You've been greeted from Rust!", name)
}

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
@watiko watiko changed the title [v2] Any blocking dialog does not display properly when running on Linux [dialog][v2][linux] Any blocking dialog does not display properly when running on Linux Feb 22, 2024
@FabianLars FabianLars added the bug Something isn't working label Feb 27, 2024
@barnabwhy
Copy link

I'm currently experiencing something at least related to this, all dialogs are causing the program to hang.
This is my code:

#[tauri::command]
fn select_file(window: Window) {
    window
        .dialog()
        .file()
        .pick_file(|_| {});
}

@barnabwhy
Copy link

I've found a workaround for the time being.

Add this to your Cargo.toml

[dependencies]
rfd = { version = "0.14.0", default-features = false, features = ["gtk3"] }

And instead of using Tauri's dialog code you can use rfd's

async fn select_file(window: Window) -> Option<String> {
    let file = AsyncFileDialog::new()
        .set_parent(&window)
        .pick_file()
        .await;

    Some(file?.path().to_str()?.to_string())
}

@z-jxy
Copy link

z-jxy commented Mar 4, 2024

still experiencing this issue on linux from a fresh project using pnpm create tauri-app --beta

> tauri "info"


[✔] Environment
    - OS: Debian 12 X64
    ✔ webkit2gtk-4.1: 2.42.5
    ✔ rsvg2: 2.54.7
    ✔ rustc: 1.77.0-nightly (11f32b73e 2024-01-31)
    ✔ cargo: 1.77.0-nightly (7bb7b5395 2024-01-20)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: nightly-x86_64-unknown-linux-gnu (default)
    - node: 18.17.1
    - pnpm: 8.15.0
    - npm: 9.6.7
    - bun: 1.0.25

[-] Packages
    - tauri [RUST]: 2.0.0-beta.8
    - tauri-build [RUST]: 2.0.0-beta.6
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.3
    - @tauri-apps/cli [NPM]: 2.0.0-beta.6

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

@Blist
Copy link

Blist commented Mar 4, 2024

I'm encountering the same issue on a fresh install of Arch Linux using either i3 or Sway (thus, both Xorg and Wayland environments). The problem persists when I switch to GNOME on Wayland. Every dialog interaction causes the application to freeze.

I'm using a project created with the native setup and the JavaScript API as follows:

import Greet from './lib/Greet.svelte';
import { open } from '@tauri-apps/plugin-dialog';

const openDialog = async () => {
  // Open a dialog
  const file = await open({
    multiple: false,
    directory: false,
  });
  console.log(file);
}

Additionally, I have experimented with different versions of tauri-plugin-dialog, ranging from 2.0.0-alpha.0 to 2.0.0-beta.1, and tried various versions of the rfd plugin (from 0.11.0 to 0.14.0) without any success.

I noticed there is an issue on the rfd project, but I'm not sure if it's related.
PolyMeilex/rfd#157

edit: I forgot the tauri info

$ tauri info

[✔] Environment
    - OS: Manjaro 23.1.3 X64
    ✔ webkit2gtk-4.1: 2.42.5
    ✔ rsvg2: 2.57.1
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 21.6.1
    - bun: 1.0.29

[-] Packages
    - tauri [RUST]: 2.0.0-beta.8
    - tauri-build [RUST]: 2.0.0-beta.6
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.6

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

@barnabwhy
Copy link

I noticed there is an issue on the rfd project, but I'm not sure if it's related. PolyMeilex/rfd#157

As mentioned by another in the rfd issue, it's likely unrelated as tauri doesn't use the xdg backend.

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

Successfully merging a pull request may close this issue.

6 participants