Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion luma-tauri/src/rust/base_invokes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,23 @@ pub async fn get_active_workspace() -> Result<Option<Project>, 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()))
Expand All @@ -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(())
}

Expand Down
8 changes: 7 additions & 1 deletion luma-tauri/src/rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -120,6 +121,8 @@ fn build_tauri_app() -> Result<tauri::App> {
// 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![
Expand Down Expand Up @@ -155,7 +158,10 @@ fn build_tauri_app() -> Result<tauri::App> {
.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")?;
Expand Down
83 changes: 83 additions & 0 deletions luma-tauri/src/rust/splash_window.rs
Original file line number Diff line number Diff line change
@@ -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<Instant> = OnceLock::new();

pub fn splash_window(app: AppHandle) -> anyhow::Result<WebviewWindow> {
// 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();
});
}
Binary file added luma-tauri/src/splash/LumaSplash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion luma-tauri/src/vite/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"noFallthroughCasesInSwitch": true,

"paths": {
"~/*": ["./*"]
"~/*": ["./*"],
"@splash/*": ["../splash/*"]
}
},
"include": [
Expand Down
8 changes: 7 additions & 1 deletion luma-tauri/src/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -22,14 +26,16 @@ 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")
}
}
},
resolve: {
alias: {
// "~" maps to the Vite project root (there is no ./src directory here).
"~": fileURLToPath(new URL(".", import.meta.url)),
"@splash": resolve(__dirname, "../splash"),
},
},
});
28 changes: 28 additions & 0 deletions luma-tauri/src/vite/vue/Splash.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue";
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
import SplashScreen from "~/vue/SplashScreen.vue";

const FADE_MS = 400;
const leaving = ref(false);

// Rust emits "splash-finish" once the startup window is shown.
const listening: Promise<UnlistenFn> = listen("splash-finish", () => {
leaving.value = true;
window.setTimeout(() => void getCurrentWindow().close(), FADE_MS);
});

async function onReady() {
// Make sure we can't miss the finish event, then ask Rust to show us.
await listening;
await invoke("webview_ready");
}

onBeforeUnmount(async () => (await listening)());
</script>

<template>
<SplashScreen :leaving="leaving" :fade-out-ms="FADE_MS" @ready="onReady" />
</template>
80 changes: 80 additions & 0 deletions luma-tauri/src/vite/vue/SplashScreen.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted } from "vue";
import splashUrl from "@splash/LumaSplash.png";

withDefaults(
defineProps<{
/** Fades the splash out when true. */
leaving?: boolean;
/** Fade-out duration (ms). */
fadeOutMs?: number;
}>(),
{
leaving: false,
fadeOutMs: 400,
}
);

/** Fired once the splash image has loaded (or failed / timed out). */
const emit = defineEmits<{ (e: "ready"): void }>();

let announced = false;
let fallbackTimer = 0;

function announce() {
if (announced) return;
announced = true;
emit("ready");
}

onMounted(() => {
// Safety net: never leave the splash window hidden forever.
fallbackTimer = window.setTimeout(announce, 2000);
});

onBeforeUnmount(() => clearTimeout(fallbackTimer));
</script>

<template>
<div
class="splash"
:class="{ leaving }"
:style="{ '--splash-fade': `${fadeOutMs}ms` }"
@contextmenu.prevent
>
<img
class="art"
:src="splashUrl"
alt="Luma"
draggable="false"
decoding="sync"
@load="announce"
@error="announce"
/>
</div>
</template>

<style scoped lang="scss">
.splash {
position: fixed;
inset: 0;
background: #0f081a; // matches the art's edge color while it loads
overflow: hidden;
user-select: none;
transition: opacity var(--splash-fade, 400ms) ease;

&.leaving {
opacity: 0;
}
}

// Art is 2550x1650 (aspect 1.545), the window is 850x550 (same aspect),
// so "cover" fills it exactly with no cropping.
.art {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
}
</style>
21 changes: 21 additions & 0 deletions luma-tauri/src/vite/windows/splash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Luma</title>
<style>
html, body, #app {
margin: 0;
width: 100%;
height: 100%;
background: #000;
overflow: hidden;
}
</style>
</head>
<body>
<div id="app"></div>
<script type="module" src="splash.ts"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions luma-tauri/src/vite/windows/splash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from "vue";
import Splash from "~/vue/Splash.vue";

createApp(Splash).mount("#app");