浏览代码

feat(docs): improve splashscreen example

Lucas Nogueira 4 年之前
父节点
当前提交
f665d001ed
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      docs/usage/guides/visual/splashscreen.md

+ 13 - 8
docs/usage/guides/visual/splashscreen.md

@@ -85,14 +85,19 @@ use tauri::Manager;
 fn main() {
   tauri::Builder::default()
     .setup(|app| {
-      // Run initialization code here
-      // ...
-
-      // 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();
+      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
+        splashscreen_window.close().unwrap();
+        main_window.show().unwrap();
+      });
       Ok(())
     })
     .run(tauri::generate_context!())