Skip to content

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

@watiko

Description

@watiko

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");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions