diff --git a/luma-tauri/src/rust/base_invokes.rs b/luma-tauri/src/rust/base_invokes.rs index 7aae128..75fdfc2 100644 --- a/luma-tauri/src/rust/base_invokes.rs +++ b/luma-tauri/src/rust/base_invokes.rs @@ -559,9 +559,23 @@ pub async fn get_active_workspace() -> Result, tauri::ipc::Invok } #[tauri::command] -pub async fn webview_ready(window: tauri::WebviewWindow) -> Result<(), tauri::ipc::InvokeError> { +pub async fn webview_ready( + app_handle: tauri::AppHandle, + window: tauri::WebviewWindow, +) -> Result<(), tauri::ipc::InvokeError> { log::info!("webview_ready label={}", window.label()); + let is_splash = window.label() == crate::splash_window::SPLASH_LABEL; + + if !is_splash { + // Keep real windows hidden until the splash has had its minimum time. + let handle = app_handle.clone(); + let _ = tauri::async_runtime::spawn_blocking(move || { + crate::splash_window::hold_until_splash_done(&handle); + }) + .await; + } + window .show() .context(format!("Failed to show the {} window", window.label())) @@ -571,6 +585,12 @@ pub async fn webview_ready(window: tauri::WebviewWindow) -> Result<(), tauri::ip .context(format!("Failed to focus the {} window", window.label())) .map_err(tauri::ipc::InvokeError::from_anyhow)?; + if is_splash { + crate::splash_window::mark_shown(); + } else { + crate::splash_window::finish(&app_handle); + } + Ok(()) } diff --git a/luma-tauri/src/rust/main.rs b/luma-tauri/src/rust/main.rs index 65e205c..0069a37 100644 --- a/luma-tauri/src/rust/main.rs +++ b/luma-tauri/src/rust/main.rs @@ -3,6 +3,7 @@ pub mod base_invokes; mod error_report; pub mod file_system; pub mod settings_window; +pub mod splash_window; pub mod startup_window; pub mod tauri_utils; @@ -120,6 +121,8 @@ fn build_tauri_app() -> Result { // full path stores window state in Roaming/Luma instead of the // bundle-identifier directory. .with_filename(window_state_path.to_string_lossy().into_owned()) + // The splash has a fixed size and position. + .with_denylist(&[splash_window::SPLASH_LABEL]) .build(), ) .invoke_handler(tauri::generate_handler![ @@ -155,7 +158,10 @@ fn build_tauri_app() -> Result { .setup(|app| { log::info!("Tauri ready"); - + // Splash first; the startup window stays hidden until the splash + // has been up for its minimum time (see base_invokes::webview_ready). + splash_window::splash_window(app.handle().clone()) + .context("Failed to initialize splash window")?; startup_window::startup_window(app.handle().clone()) .context("Failed to initialize startup window")?; diff --git a/luma-tauri/src/rust/splash_window.rs b/luma-tauri/src/rust/splash_window.rs new file mode 100644 index 0000000..8003e1d --- /dev/null +++ b/luma-tauri/src/rust/splash_window.rs @@ -0,0 +1,83 @@ +use anyhow::Context; +use std::sync::OnceLock; +use std::time::{Duration, Instant}; +use tauri::webview::Color; +use tauri::{AppHandle, Emitter, Manager, WebviewUrl, WebviewWindow, WebviewWindowBuilder}; + +pub const SPLASH_LABEL: &str = "splash"; + +/// Minimum time the splash stays on screen once it is visible. +const MIN_VISIBLE: Duration = Duration::from_millis(2500); +/// How long other windows will wait for the splash to appear before giving up. +const MAX_WAIT_FOR_SPLASH: Duration = Duration::from_secs(3); +/// Splash is force-closed this long after "splash-finish" if it didn't close itself. +const FORCE_CLOSE_AFTER: Duration = Duration::from_millis(1500); + +static SHOWN_AT: OnceLock = OnceLock::new(); + +pub fn splash_window(app: AppHandle) -> anyhow::Result { + // 850x550 matches the 2550x1650 splash art at 3x. + WebviewWindowBuilder::new( + &app, + SPLASH_LABEL, + WebviewUrl::App("windows/splash.html".into()), + ) + .visible(false) + .decorations(false) + .resizable(false) + .maximizable(false) + .minimizable(false) + .shadow(true) + .always_on_top(true) + .skip_taskbar(true) + .center() + .inner_size(850.0, 550.0) + .title("Luma") + .background_color(Color(0, 0, 0, 255)) + .build() + .context("Failed to build splash window") +} + +/// Called when the splash window has been shown. +pub fn mark_shown() { + let _ = SHOWN_AT.set(Instant::now()); +} + +/// Blocks (call from a blocking thread) until the splash has been visible for +/// at least `MIN_VISIBLE`. Returns immediately if there is no splash. +pub fn hold_until_splash_done(app: &AppHandle) { + let started = Instant::now(); + + // The splash page may still be loading; wait for it to show up. + while SHOWN_AT.get().is_none() { + if app.get_webview_window(SPLASH_LABEL).is_none() + || started.elapsed() > MAX_WAIT_FOR_SPLASH + { + return; + } + std::thread::sleep(Duration::from_millis(25)); + } + + if let Some(shown) = SHOWN_AT.get() { + let elapsed = shown.elapsed(); + if elapsed < MIN_VISIBLE { + std::thread::sleep(MIN_VISIBLE - elapsed); + } + } +} + +/// Tells the splash to fade out and close, with a hard fallback. +pub fn finish(app: &AppHandle) { + let Some(splash) = app.get_webview_window(SPLASH_LABEL) else { + return; + }; + + if let Err(error) = app.emit_to(SPLASH_LABEL, "splash-finish", ()) { + log::warn!("Failed to emit splash-finish: {error}"); + } + + std::thread::spawn(move || { + std::thread::sleep(FORCE_CLOSE_AFTER); + let _ = splash.close(); + }); +} diff --git a/luma-tauri/src/splash/LumaSplash.png b/luma-tauri/src/splash/LumaSplash.png new file mode 100644 index 0000000..d097b0a Binary files /dev/null and b/luma-tauri/src/splash/LumaSplash.png differ diff --git a/luma-tauri/src/vite/tsconfig.app.json b/luma-tauri/src/vite/tsconfig.app.json index b5cd27e..8a37284 100644 --- a/luma-tauri/src/vite/tsconfig.app.json +++ b/luma-tauri/src/vite/tsconfig.app.json @@ -12,7 +12,8 @@ "noFallthroughCasesInSwitch": true, "paths": { - "~/*": ["./*"] + "~/*": ["./*"], + "@splash/*": ["../splash/*"] } }, "include": [ diff --git a/luma-tauri/src/vite/vite.config.ts b/luma-tauri/src/vite/vite.config.ts index 5ab7d40..c3dbd3b 100644 --- a/luma-tauri/src/vite/vite.config.ts +++ b/luma-tauri/src/vite/vite.config.ts @@ -13,6 +13,10 @@ export default defineConfig({ server: { port: 1420, strictPort: true, + fs: { + // Allow importing from ../splash (outside the Vite root). + allow: [resolve(__dirname, "..")], + }, }, build: { @@ -22,7 +26,8 @@ export default defineConfig({ input: { main: resolve(__dirname, "windows" ,"main.html"), settings: resolve(__dirname, "windows", "settings.html"), - startup: resolve(__dirname, "windows", "startup.html") + startup: resolve(__dirname, "windows", "startup.html"), + splash: resolve(__dirname, "windows", "splash.html") } } }, @@ -30,6 +35,7 @@ export default defineConfig({ alias: { // "~" maps to the Vite project root (there is no ./src directory here). "~": fileURLToPath(new URL(".", import.meta.url)), + "@splash": resolve(__dirname, "../splash"), }, }, }); \ No newline at end of file diff --git a/luma-tauri/src/vite/vue/Splash.vue b/luma-tauri/src/vite/vue/Splash.vue new file mode 100644 index 0000000..d267876 --- /dev/null +++ b/luma-tauri/src/vite/vue/Splash.vue @@ -0,0 +1,28 @@ + + + diff --git a/luma-tauri/src/vite/vue/SplashScreen.vue b/luma-tauri/src/vite/vue/SplashScreen.vue new file mode 100644 index 0000000..8f74fc5 --- /dev/null +++ b/luma-tauri/src/vite/vue/SplashScreen.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/luma-tauri/src/vite/windows/splash.html b/luma-tauri/src/vite/windows/splash.html new file mode 100644 index 0000000..53e9c10 --- /dev/null +++ b/luma-tauri/src/vite/windows/splash.html @@ -0,0 +1,21 @@ + + + + + + Luma + + + +
+ + + diff --git a/luma-tauri/src/vite/windows/splash.ts b/luma-tauri/src/vite/windows/splash.ts new file mode 100644 index 0000000..4d03c1e --- /dev/null +++ b/luma-tauri/src/vite/windows/splash.ts @@ -0,0 +1,4 @@ +import { createApp } from "vue"; +import Splash from "~/vue/Splash.vue"; + +createApp(Splash).mount("#app");