Describe the bug
Creating this off the heels of #3883 - I noticed that the app hangs if I do window operations in a non-async Tauri command on Windows. Making the command async fixes the problem.
This is the command that hangs:
#[tauri::command]
pub fn open_activation_window(app: tauri::AppHandle) {
if let Some(window) = app.get_window(ACTIVATION_WINDOW_LABEL) {
let _ = window.set_focus();
let _ = window.center();
} else {
let window = tauri::window::WindowBuilder::new(
&app,
ACTIVATION_WINDOW_LABEL,
tauri::WindowUrl::App("activation.html".into()),
)
.title("Activate Recut")
.center()
.focus()
.inner_size(500.0, 300.0)
.resizable(false)
.build()
.map_err(|e| e.to_string())?;
// hide the menu
let _ = window.menu_handle().toggle();
}
}
This version of it works:
#[tauri::command]
pub async fn open_activation_window(app: tauri::AppHandle) -> Result<(), String> {
if let Some(window) = app.get_window(ACTIVATION_WINDOW_LABEL) {
let _ = window.set_focus();
let _ = window.center();
} else {
let window = tauri::window::WindowBuilder::new(
&app,
ACTIVATION_WINDOW_LABEL,
tauri::WindowUrl::App("activation.html".into()),
)
.title("Activate Recut")
.center()
.focus()
.inner_size(500.0, 300.0)
.resizable(false)
.build()
.map_err(|e| e.to_string())?;
// hide the menu
let _ = window.menu_handle().toggle();
}
Ok(())
}
Reproduction
- Create a Tauri app that includes that includes the non-async
open_activation_window command.
- Invoke that command from JS
Expected behavior
It should open the window. And according to Lucas, it should be able to do this on the main thread.
Platform and versions
Environment
› OS: Windows 10.0.19044 X64
› Webview2: 101.0.1210.39
› MSVC:
- Visual Studio Build Tools 2019
- Visual Studio Community 2019
› Node.js: 16.9.0
› npm: 7.22.0
› pnpm: Not installed!
› yarn: 1.22.17
› rustup: 1.24.3
› rustc: 1.60.0
› cargo: 1.60.0
› Rust toolchain: stable-x86_64-pc-windows-msvc
Packages
› @tauri-apps/cli [NPM]: 1.0.0-rc.10
› @tauri-apps/api [NPM]: 1.0.0-rc.3
› tauri [RUST]: 1.0.0-rc.10,
› tauri-build [RUST]: 1.0.0-rc.8,
› tao [RUST]: 0.8.4,
› wry [RUST]: 0.16.2,
App
› build-type: bundle
› CSP: unset
› distDir: ../build
› devPath: http://localhost:3000/
› framework: Svelte
› bundler: Rollup
App directory structure
├─ .vscode
├─ build
├─ node_modules
├─ public
├─ scripts
├─ src
└─ src-tauri
Done in 5.99s.
Stack trace
No response
Additional context
No response
Describe the bug
Creating this off the heels of #3883 - I noticed that the app hangs if I do window operations in a non-async Tauri command on Windows. Making the command
asyncfixes the problem.This is the command that hangs:
This version of it works:
Reproduction
open_activation_windowcommand.Expected behavior
It should open the window. And according to Lucas, it should be able to do this on the main thread.
Platform and versions
Environment › OS: Windows 10.0.19044 X64 › Webview2: 101.0.1210.39 › MSVC: - Visual Studio Build Tools 2019 - Visual Studio Community 2019 › Node.js: 16.9.0 › npm: 7.22.0 › pnpm: Not installed! › yarn: 1.22.17 › rustup: 1.24.3 › rustc: 1.60.0 › cargo: 1.60.0 › Rust toolchain: stable-x86_64-pc-windows-msvc Packages › @tauri-apps/cli [NPM]: 1.0.0-rc.10 › @tauri-apps/api [NPM]: 1.0.0-rc.3 › tauri [RUST]: 1.0.0-rc.10, › tauri-build [RUST]: 1.0.0-rc.8, › tao [RUST]: 0.8.4, › wry [RUST]: 0.16.2, App › build-type: bundle › CSP: unset › distDir: ../build › devPath: http://localhost:3000/ › framework: Svelte › bundler: Rollup App directory structure ├─ .vscode ├─ build ├─ node_modules ├─ public ├─ scripts ├─ src └─ src-tauri Done in 5.99s.Stack trace
No response
Additional context
No response