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.
#[tauri::command]
pub async fn close_splashscreen(window: Window) {
println!("Closing splashscreen");
// Close splashscreen
window
.get_window("splashscreen")
.expect("no window labeled 'splashscreen' found")
.close()
.unwrap();
// Show main window
window
.get_window("main")
.expect("no window labeled 'main' found")
.show()
.unwrap();
match window.get_window("splashscreen") {
Some(window) => window.close().unwrap(),
None => tracing::info!("Couldn't find splashscreen window"),
}
match window.get_window("main") {
Some(window) => window.show().unwrap(),
None => tracing::info!("Couldn't find main window"),
}
}

View file

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

View file

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

View file

@ -9,11 +9,16 @@
import { onDestroy, onMount } from 'svelte'
import { Toaster } from 'svelte-french-toast'
import { initializationSequence } from './lib/Sequences/sequences'
import Loading from './lib/Loading/Loading.svelte'
import { settingsStore } from './lib/stores/settingsStore'
import getSettings from './lib/utils/getSettings'
import hideSplashscreen from './lib/utils/hideSplashscreen'
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
@ -27,22 +32,39 @@
initializeTelemetry().then((unsubFunction: () => void) => {
unlistenAll = unsubFunction
})
setTimeout(initializationSequence, 3000)
settingsStore.subscribe((value) => {
localStorage.setItem('settings', JSON.stringify(value))
})
setTimeout(() => {
fakeLoadingDone = true
}, 3000)
})
onDestroy(() => {
unlistenAll && unlistenAll()
})
const start = () => {
hideSplashscreen()
initializationSequence()
}
const onVisualizationLoaded = () => {
realLoadingDone = true
}
$: if (realLoadingDone && fakeLoadingDone && !started) {
started = true
start()
}
</script>
<main class="select-none transition-opacity duration-300">
<!-- driver dashboard -->
<div class="h-screen w-[35vw] fixed shadow-lg shadow-slate-800 z-10">
<Dashboard />
<Dashboard on:loaded={onVisualizationLoaded} />
</div>
<!-- the infotainment system -->
<div class="min-h-screen w-[65vw] right-0 absolute infotainment-container">

View file

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

View file

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

View file

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

View file

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