Passa al contenuto principale


If your webpage could take some time to load, or if you need to run an initialization procedure in Rust before displaying your main window, a splashscreen could improve the loading experience for the user.


First, create a splashscreen.html in your distDir that contains the HTML code for a splashscreen. Then, update your tauri.conf.json like so:

"windows": [
"title": "Tauri App",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false,
+ "visible": false // Hide the main window by default
// Add the splashscreen window
+ {
+ "width": 400,
+ "height": 200,
+ "decorations": false,
+ "url": "splashscreen.html",
+ "label": "splashscreen"
+ }

Now, your main window will be hidden and the splashscreen window will show when your app is launched. Next, you'll need a way to close the splashscreen and show the main window when your app is ready. How you do this depends on what you are waiting for before closing the splashscreen.

Waiting for Webpage​

If you are waiting for your web code, you'll want to create a close_splashscreen command.

use tauri::Manager;
// Create the command:
// This command must be async so that it doesn't run on the main thread.
async fn close_splashscreen(window: tauri::Window) {
// Close splashscreen
if let Some(splashscreen) = window.get_window("splashscreen") {
// Show main window

// Register the command:
fn main() {
// Add this line
.expect("failed to run app");

You can then import it to your project in one of two ways:

// With the Tauri API npm package:
import { invoke } from '@tauri-apps/api/tauri'


// With the Tauri global script:
const invoke = window.__TAURI__.invoke

And finally, add an Event Listener (or just call invoke() whenever you want):

document.addEventListener('DOMContentLoaded', () => {
// This will wait for the window to load, but you could
// run this function on whatever trigger you want

Waiting for Rust​

If you are waiting for Rust code to run, put it in the setup function handler so you have access to the App instance:

use tauri::Manager;
fn main() {
.setup(|app| {
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!("Done initializing.");

// After it's done, close the splashscreen and display the main window
.expect("failed to run app");