Skip to content

Support async commands with Window handle on Windows #2078

@TomzBench

Description

@TomzBench

Is your feature request related to a problem? Please describe.
I have an async [tauri::command] that includes a Window. This command compiles on Linux, but not compile on Windows. On Windows I get an error that Window is not Send and not Sync.

Describe the solution you'd like
Window object on Windows should be Send + Sync as same on Linux.

Additional context

Here is the code that compiles on Linux, but does not compile on Windows

#[tauri::command]
pub async fn update<'r>(
  io: tauri::State<'r, Io>,
  window: tauri::Window,
  serial: String,
  update: Update,
) -> Result<(), String> {
  let mut count = 0;
  let total = update.len();
  io.channel(&serial)
    .map_err(|e| e.to_string())?
    .requests(update)
    .try_for_each(|_| {
      count = count + 1;
      window
        .emit(
          "update",
          Some(UpdateProgress {
            serial: serial.clone(),
            count,
            total,
          }),
        )
        .expect("failed to emit update status");
      future::ready(Ok(()))
    })
    .map_err(|e| e.to_string())
    .await?;
  Ok(())
}

Here are some clips of the compiler errors

13 |   #[tauri::command]
   |   ^^^^^^^^^^^^^^^^^ future returned by `update` is not `Send`

   = help: within `tauri::Window`, the trait `std::marker::Sync` is not implemented for `*mut winapi::shared::windef::HWND__`
note: future is not `Send` as this value is used across an await

   = help: within `tauri::Window`, the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<tauri_runtime_wry::Message>`
note: future is not `Send` as this value is used across an await

[Windows info]

Operating System - Windows, version 10.0.19041 X64
Webview2 - 91.0.864.54

Node.js environment
  Node.js - 14.15.4
  @tauri-apps/cli - 1.0.0-beta.1 (outdated, latest: 1.0.0-beta.3)
  @tauri-apps/api - Not installed

Global packages
  npm - 6.14.10
  yarn - 1.22.10

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/src
/src-tauri

App
  tauri.rs - 1.0.0-beta.2
build-type - bundle
CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
distDir - ../../../dist/app-companion/
devPath - http://localhost:4500

[Linux info]

Operating System - Fedora, version 32.0.0 X64

Node.js environment
  Node.js - 14.17.0
  @tauri-apps/cli - 1.0.0-beta.1 (outdated, latest: 1.0.0-beta.3)
  @tauri-apps/api - Not installed

Global packages
  npm - 6.14.13
  yarn - 1.22.10

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/src
/src-tauri

App
  tauri.rs - 1.0.0-beta.2
build-type - bundle
CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
distDir - ../../../dist/app-companion/
devPath - http://localhost:4500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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