From f665d001ed954460f70d05d97f7616a07c52ddde Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 13 Aug 2021 10:09:43 -0300 Subject: [PATCH] feat(docs): improve splashscreen example --- docs/usage/guides/visual/splashscreen.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/usage/guides/visual/splashscreen.md b/docs/usage/guides/visual/splashscreen.md index f2cfefca7..a2738fb87 100644 --- a/docs/usage/guides/visual/splashscreen.md +++ b/docs/usage/guides/visual/splashscreen.md @@ -85,14 +85,19 @@ use tauri::Manager; fn main() { tauri::Builder::default() .setup(|app| { - // Run initialization code here - // ... + let splashscreen_window = app.get_window("splashscreen").unwrap(); + let main_window = app.get_window("main").unwrap(); + // we perform the initialization code on a new task so the app doesn't freeze + tauri::async_runtime::spawn(async move { + // initialize your app here instead of sleeping :) + println!("Initializing..."); + std::thread::sleep(std::time::Duration::from_secs(2)); + println!("Done initializing."); - // After it's done, close the splashscreen and display the main window - if let Some(splashscreen) = app.get_window("splashscreen") { - splashscreen.close().unwrap(); - } - app.get_window("main").unwrap().show().unwrap(); + // After it's done, close the splashscreen and display the main window + splashscreen_window.close().unwrap(); + main_window.show().unwrap(); + }); Ok(()) }) .run(tauri::generate_context!())