Search code examples
rustwindowruntimetauri

WindowBuilder doesn't open a new window


Trying to open a new window in Tauri outside of the runtime and setup function.

let result = tauri::WindowBuilder
                ::new(handle.app_handle(), "main", tauri::WindowUrl::App("index.html".into()))
                .title("Demo")
                .resizable(true)
                .fullscreen(false)
                .inner_size(1200.0, 800.0)
                .min_inner_size(400.0, 400.0)
                .build();

But it doesn't open the window outside of the Tauri's Runtime.


Solution

  • Similar to this post

    it looks like the window creation has to be done from the async function. But unlike the above post, this issue also appears on Mac, not just Windows.

    tokio::spawn(async move {
         let result = tauri::WindowBuilder::new(handle, "main", tauri::WindowUrl::App("index.html".into()))
             .title("Demo")
             .resizable(true)
             .fullscreen(false)
             .inner_size(1200.0, 800.0)
             .min_inner_size(400.0, 400.0)
             .build();
    });