splash screen

This commit is contained in:
Greg Shuflin 2024-10-06 01:46:01 -07:00
parent 17abe0b71d
commit 052251be03
5 changed files with 53 additions and 2 deletions

1
src-tauri/Cargo.lock generated
View File

@ -1049,6 +1049,7 @@ dependencies = [
"tauri-plugin-http", "tauri-plugin-http",
"tauri-plugin-os", "tauri-plugin-os",
"tauri-plugin-shell", "tauri-plugin-shell",
"tokio",
"tracing", "tracing",
"tracing-appender", "tracing-appender",
"tracing-subscriber", "tracing-subscriber",

View File

@ -27,4 +27,5 @@ tracing = "0.1.40"
tracing-subscriber = "0.3.18" tracing-subscriber = "0.3.18"
tauri-plugin-http = "2" tauri-plugin-http = "2"
tracing-appender = "0.2.3" tracing-appender = "0.2.3"
tokio = "1.40.0"

View File

@ -1,4 +1,8 @@
use std::time::Duration;
use tauri::{async_runtime::spawn, AppHandle, Manager};
use tauri_plugin_http::reqwest; use tauri_plugin_http::reqwest;
use tokio::{time::sleep};
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command] #[tauri::command]
@ -23,6 +27,17 @@ async fn quote() -> String {
text 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)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tracing::info!("Starting up tauri app"); tracing::info!("Starting up tauri app");
@ -31,6 +46,18 @@ pub fn run() {
.plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet, os_info, quote]) .invoke_handler(tauri::generate_handler![greet, os_info, quote])
.setup(|app| {
spawn(setup(app.handle().clone()));
Ok(())
})
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .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(())
}

View File

@ -10,10 +10,15 @@
"withGlobalTauri": true, "withGlobalTauri": true,
"windows": [ "windows": [
{ {
"label": "main",
"title": "gensoukyou-tauri", "title": "gensoukyou-tauri",
"width": 800, "width": 800,
"height": 600 "height": 600,
"visible": false
},
{
"label": "splashscreen",
"url": "/splashscreen"
} }
], ],
"security": { "security": {

17
src/splashscreen.html Normal file
View File

@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/src/styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri App</title>
</head>
<body>
<div class="container">
<h1>Tauri used Splash!</h1>
<div class="row">
<h5>It was super effective!</h5>
</div>
</div>
</body>
</html>