1

I am using Tauri's WindowBuilder to try and create a new window in Rust. While I was able to generate a blank window, I am unable to:

  • display any content on the window
  • make the window close

I am fairly new with Rust and Tauri so forgive me if these problems seem trivial. There does not seem to be much about it online, so I was hoping someone out there could help me out. Thank you in advance.

Here is the command I have written within /src-tauri/src/main.rs to open what will become a settings window:

#[tauri::command]
fn open_settings_window(app: AppHandle) -> Result<(), String> {
    let result = WindowBuilder::new(&app, "settings", WindowUrl::App("Settings.tsx".into()))
        .fullscreen(false)
        .resizable(true)
        .title("Settings")
        .center()
        .build();
    match result {
        Ok(_) => {
            println!("Window Created Successfully!");
            Ok(())
        }
        Err(err) => {
            println!("Failed to Create Window {}", err);
            Err("Failed to create Window".to_string())
        }
    }
}

Within the main function I have created the necessary invoke handler: .invoke_handler(tauri::generate_handler![open_settings_window])

Within my App.tsx file, the window is set to open onClick in the following manner: <button type='button' onClick={() => invoke('open_settings_window')}>SETTINGS</button>

What I have tried:

  1. I have tried changing the WindowUrl::App() path to a static html file as well as a .tsx file as show above and nothing will display in the window. (even with path navigation like ../ or ./ etc.)
  2. I have explored the WindowBuilder docs to find a solution and there is none that are apparent to me: https://docs.rs/tauri/latest/tauri/window/struct.WindowBuilder.html

Please help!

pdox
  • 31
  • 3

1 Answers1

2

Okay so as it turns out, the docs actually state the solution pretty clearly:

"Known issues On Windows, this function deadlocks when used in a synchronous command, see the Webview2 issue. You should use async commands when creating windows."

I am unsure why I didn't see this until now but I figure I'll answer my own question and leave it here in case anyone else misses it. The fix is to change the method header as follows:

#[tauri::command]
async fn open_settings_window(app: AppHandle) -> Result<(), String>

Happy Coding!

pdox
  • 31
  • 3