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

Multi window freeze #2311

Closed
probablykasper opened this issue Jul 28, 2021 · 6 comments
Closed

Multi window freeze #2311

probablykasper opened this issue Jul 28, 2021 · 6 comments

Comments

@probablykasper
Copy link
Member

Describe the bug

Creating a new window like this makes the app unresponsive on macOS:

#[command]
pub fn new_window(app_handle: AppHandle) -> Result<(), String> {
  println!("new w");
  app_handle
    .create_window("main2".to_string(), WindowUrl::default(), |win, webview| {
      let win = win
        .title("Main 2")
        .resizable(true)
        .transparent(false)
        .decorations(true)
        .always_on_top(false)
        .inner_size(800.0, 600.0)
        .min_inner_size(300.0, 150.0)
        .fullscreen(false);
      println!("- struct created");
      return (win, webview);
    })
    .expect("Error creating window");
  println!("- done");
  Ok(())
}

To Reproduce

Repo: https://github.com/probablykasper/tauri-multiwindow-freeze-bug

Platform and Versions (required):

Operating System - Mac OS, version 10.15.7 X64

Node.js environment
  Node.js - 14.16.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 6.14.11
  yarn - 1.22.10

Rust environment
  rustc - 1.52.1
  cargo - 1.52.0

App directory structure
/node_modules
/src-tauri
/build
/.git
/src

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../build
  devPath - http://localhost:4000
  framework - Svelte
@amrbashir
Copy link
Member

I can reproduce this issue on windows with your repo but can't reproduce it with our multiwindow example.

@probablykasper
Copy link
Member Author

@amrbashir I think the multiwindow example only creates windows from tauri.conf.json and/or tauri::Builder

@amrbashir
Copy link
Member

amrbashir commented Jul 28, 2021

No, it creates from commands too.
Edit: it creates it from the js side.

@probablykasper
Copy link
Member Author

@amrbashir Ah, so then it calls this internal command:

Self::CreateWebview { options } => {
let mut window = window;
let label = options.label.clone();
let url = options.url.clone();
window
.create_window(label.clone(), url, |_, webview_attributes| {
(
<<R::Dispatcher as Dispatch>::WindowBuilder>::with_config(options),
webview_attributes,
)
})?
.emit_others("tauri://window-created", Some(WindowCreatedEvent { label }))?;
}

@amrbashir
Copy link
Member

amrbashir commented Jul 28, 2021

@amrbashir Ah, so then it calls this internal command:

yeah but we still need to figure out why it doesn't work from commands, doesn't matter which attributes you set too

#[command]
pub fn new_window(app_handle: AppHandle) -> Result<(), String> {
  println!("new w");
  app_handle
    .create_window("main2".to_string(), WindowUrl::default(), |win, webview| (win, webview))
    .expect("Error creating window");
  println!("- done");
  Ok(())
}

@lucasfernog
Copy link
Member

It doesn't work because the command is not async, which means it is ran on the main thread and it's preventing the event loop from receiving the message.

Changing the #[command] pub fn to #[command] pub async fn will make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants