feat: hide splashscreen when robot model loads

This commit is contained in:
Youwen Wu 2024-03-11 00:13:50 -07:00
parent e0aceea3cf
commit c19410e7f3
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
8 changed files with 51 additions and 28 deletions

View file

@ -3,16 +3,15 @@ use tauri::{Manager, Window};
// This command must be async so that it doesn't run on the main thread. // This command must be async so that it doesn't run on the main thread.
#[tauri::command] #[tauri::command]
pub async fn close_splashscreen(window: Window) { pub async fn close_splashscreen(window: Window) {
println!("Closing splashscreen");
// Close splashscreen // Close splashscreen
window match window.get_window("splashscreen") {
.get_window("splashscreen") Some(window) => window.close().unwrap(),
.expect("no window labeled 'splashscreen' found") None => tracing::info!("Couldn't find splashscreen window"),
.close() }
.unwrap();
// Show main window match window.get_window("main") {
window Some(window) => window.show().unwrap(),
.get_window("main") None => tracing::info!("Couldn't find main window"),
.expect("no window labeled 'main' found") }
.show()
.unwrap();
} }

View file

@ -5,6 +5,7 @@ use tauri::Manager;
mod telemetry; mod telemetry;
use tracing_subscriber::FmtSubscriber; use tracing_subscriber::FmtSubscriber;
mod close_splashscreen; mod close_splashscreen;
use close_splashscreen::close_splashscreen;
#[derive(Clone, serde::Serialize)] #[derive(Clone, serde::Serialize)]
struct Payload { struct Payload {
@ -24,13 +25,6 @@ fn main() {
tracing::subscriber::set_global_default(subscriber).unwrap(); tracing::subscriber::set_global_default(subscriber).unwrap();
rt.block_on(async { rt.block_on(async {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
close_splashscreen::close_splashscreen
])
.run(tauri::generate_context!())
.expect("failed to run app");
tauri::Builder::default() tauri::Builder::default()
.setup(|app| { .setup(|app| {
// create app handle and send it to our event listeners // create app handle and send it to our event listeners
@ -42,6 +36,7 @@ fn main() {
Ok(()) Ok(())
}) })
.invoke_handler(tauri::generate_handler![close_splashscreen])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("failed to run app") .expect("failed to run app")
}) })

View file

@ -1,8 +1,8 @@
{ {
"$schema": "../node_modules/@tauri-apps/cli/schema.json", "$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": { "build": {
"beforeBuildCommand": "npm run build", "beforeBuildCommand": "pnpm build",
"beforeDevCommand": "npm run dev", "beforeDevCommand": "pnpm dev",
"devPath": "http://localhost:5173", "devPath": "http://localhost:5173",
"distDir": "../dist" "distDir": "../dist"
}, },
@ -63,7 +63,8 @@
"resizable": true, "resizable": true,
"title": "Jankboard 2", "title": "Jankboard 2",
"width": 800, "width": 800,
"visible": false "visible": false,
"label": "main"
}, },
{ {
"fullscreen": false, "fullscreen": false,
@ -74,7 +75,8 @@
"resizable": true, "resizable": true,
"width": 800, "width": 800,
"url": "splashscreen.html", "url": "splashscreen.html",
"label": "splashscreen" "label": "splashscreen",
"visible": true
} }
] ]
} }

View file

@ -9,11 +9,16 @@
import { onDestroy, onMount } from 'svelte' import { onDestroy, onMount } from 'svelte'
import { Toaster } from 'svelte-french-toast' import { Toaster } from 'svelte-french-toast'
import { initializationSequence } from './lib/Sequences/sequences' import { initializationSequence } from './lib/Sequences/sequences'
import Loading from './lib/Loading/Loading.svelte'
import { settingsStore } from './lib/stores/settingsStore' import { settingsStore } from './lib/stores/settingsStore'
import getSettings from './lib/utils/getSettings' import getSettings from './lib/utils/getSettings'
import hideSplashscreen from './lib/utils/hideSplashscreen'
let activeApp: App = 'camera' let activeApp: App = 'camera'
// fake loading splash screen to look cool if the model loads too fast
let fakeLoadingDone = false
// and the real one, to wait for massive robot model to load if it's slow
let realLoadingDone = false
let started = false
let unlistenAll: () => void let unlistenAll: () => void
@ -27,22 +32,39 @@
initializeTelemetry().then((unsubFunction: () => void) => { initializeTelemetry().then((unsubFunction: () => void) => {
unlistenAll = unsubFunction unlistenAll = unsubFunction
}) })
setTimeout(initializationSequence, 3000)
settingsStore.subscribe((value) => { settingsStore.subscribe((value) => {
localStorage.setItem('settings', JSON.stringify(value)) localStorage.setItem('settings', JSON.stringify(value))
}) })
setTimeout(() => {
fakeLoadingDone = true
}, 3000)
}) })
onDestroy(() => { onDestroy(() => {
unlistenAll && unlistenAll() unlistenAll && unlistenAll()
}) })
const start = () => {
hideSplashscreen()
initializationSequence()
}
const onVisualizationLoaded = () => {
realLoadingDone = true
}
$: if (realLoadingDone && fakeLoadingDone && !started) {
started = true
start()
}
</script> </script>
<main class="select-none transition-opacity duration-300"> <main class="select-none transition-opacity duration-300">
<!-- driver dashboard --> <!-- driver dashboard -->
<div class="h-screen w-[35vw] fixed shadow-lg shadow-slate-800 z-10"> <div class="h-screen w-[35vw] fixed shadow-lg shadow-slate-800 z-10">
<Dashboard /> <Dashboard on:loaded={onVisualizationLoaded} />
</div> </div>
<!-- the infotainment system --> <!-- the infotainment system -->
<div class="min-h-screen w-[65vw] right-0 absolute infotainment-container"> <div class="min-h-screen w-[65vw] right-0 absolute infotainment-container">

View file

@ -45,7 +45,7 @@
</div> </div>
<div class="left-0 mt-2 h-[475px] w-[35vw]"> <div class="left-0 mt-2 h-[475px] w-[35vw]">
<Visualization /> <Visualization on:loaded />
</div> </div>
<Bottom> <Bottom>

View file

@ -11,6 +11,9 @@
import RobotDecimated from './models/RobotDecimated.svelte' import RobotDecimated from './models/RobotDecimated.svelte'
import { telemetryReadonlyStore } from '../../stores/telemetryStore' import { telemetryReadonlyStore } from '../../stores/telemetryStore'
import { DEG2RAD } from 'three/src/math/MathUtils.js' import { DEG2RAD } from 'three/src/math/MathUtils.js'
import { createEventDispatcher } from 'svelte'
const dispatch = createEventDispatcher()
const SPEED_MULTIPLIER = 4 const SPEED_MULTIPLIER = 4
const axis = new Vector3(0, 1, 0) const axis = new Vector3(0, 1, 0)
@ -137,6 +140,7 @@
on:create={({ ref }) => { on:create={({ ref }) => {
// @ts-expect-error // @ts-expect-error
mesh.set(ref) mesh.set(ref)
dispatch('loaded')
}} }}
/> />

View file

@ -4,5 +4,5 @@
</script> </script>
<Canvas> <Canvas>
<Scene /> <Scene on:loaded />
</Canvas> </Canvas>

View file

@ -1,5 +1,6 @@
import { invoke } from '@tauri-apps/api/tauri' import { invoke } from '@tauri-apps/api/tauri'
export default async () => { export default async () => {
await invoke('hide_splashscreen') console.log('hiding')
await invoke('close_splashscreen')
} }