diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6fc9e08..1c93bae 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1049,6 +1049,7 @@ dependencies = [ "tauri-plugin-http", "tauri-plugin-os", "tauri-plugin-shell", + "tokio", "tracing", "tracing-appender", "tracing-subscriber", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c8c936d..83db560 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,4 +27,5 @@ tracing = "0.1.40" tracing-subscriber = "0.3.18" tauri-plugin-http = "2" tracing-appender = "0.2.3" +tokio = "1.40.0" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 22499a4..3cdab1d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,8 @@ +use std::time::Duration; + +use tauri::{async_runtime::spawn, AppHandle, Manager}; use tauri_plugin_http::reqwest; +use tokio::{time::sleep}; // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command #[tauri::command] @@ -23,6 +27,17 @@ async fn quote() -> String { text } +#[tauri::command] +async fn setup_complete(app: AppHandle) -> Result<(), ()> { + + let splash_window = app.get_webview_window("splashscreen").unwrap(); + let main_window = app.get_webview_window("main").unwrap(); + splash_window.close().unwrap(); + main_window.show().unwrap(); + + Ok(()) +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tracing::info!("Starting up tauri app"); @@ -31,6 +46,18 @@ pub fn run() { .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_shell::init()) .invoke_handler(tauri::generate_handler![greet, os_info, quote]) + .setup(|app| { + spawn(setup(app.handle().clone())); + Ok(()) + }) .run(tauri::generate_context!()) .expect("error while running tauri application"); } + +async fn setup(app: AppHandle) -> Result<(), ()> { + tracing::info!("Faking a lengthy setup"); + sleep(Duration::from_secs(3)).await; + tracing::info!("Setup complete"); + setup_complete(app).await?; + Ok(()) +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 729ea24..21271b3 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -10,10 +10,15 @@ "withGlobalTauri": true, "windows": [ { + "label": "main", "title": "gensoukyou-tauri", "width": 800, - "height": 600 - + "height": 600, + "visible": false + }, + { + "label": "splashscreen", + "url": "/splashscreen" } ], "security": { diff --git a/src/splashscreen.html b/src/splashscreen.html new file mode 100644 index 0000000..bf33520 --- /dev/null +++ b/src/splashscreen.html @@ -0,0 +1,17 @@ + + + + + + + Tauri App + + +
+

Tauri used Splash!

+
+
It was super effective!
+
+
+ +