splashscreen
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
"control-panel-action-*",
|
||||
"debug",
|
||||
"onboarding",
|
||||
"scene"
|
||||
"scene",
|
||||
"splashscreen"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
|
||||
@@ -14,6 +14,8 @@ pub async fn init(handle: &AppHandle) -> Result<(), String> {
|
||||
.await
|
||||
.map_err(crate::db::command_error)?;
|
||||
|
||||
crate::ui::splashscreen::close(handle).await?;
|
||||
|
||||
if settings.onboarding_done {
|
||||
start(handle).await;
|
||||
if cfg!(target_os = "macos") && !accessibility_permission_granted {
|
||||
|
||||
+11
-3
@@ -19,8 +19,7 @@ mod ui;
|
||||
mod updater;
|
||||
mod user;
|
||||
|
||||
async fn launch_app(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let handle = app.handle();
|
||||
async fn launch_app(handle: &tauri::AppHandle) -> Result<(), Box<dyn std::error::Error>> {
|
||||
updater::init(handle).await;
|
||||
db::init(handle).await?;
|
||||
scene_configuration::init(handle).await?;
|
||||
@@ -54,7 +53,16 @@ pub fn run() {
|
||||
.invoke_handler(specta_builder.invoke_handler())
|
||||
.setup(move |app| {
|
||||
specta_builder.mount_events(app);
|
||||
tauri::async_runtime::block_on(launch_app(app))?;
|
||||
let handle = app.handle().clone();
|
||||
ui::splashscreen::open(&handle)?;
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let launch_result = launch_app(&handle).await.map_err(|error| error.to_string());
|
||||
|
||||
if let Err(error) = launch_result {
|
||||
eprintln!("failed to launch application: {error}");
|
||||
handle.exit(1);
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.build(tauri::generate_context!())
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod control_panel;
|
||||
mod debug;
|
||||
pub mod onboarding;
|
||||
pub mod scene;
|
||||
pub mod splashscreen;
|
||||
mod tray;
|
||||
|
||||
pub fn init(app_handle: &AppHandle) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use tauri::{AppHandle, Manager, WebviewUrl};
|
||||
|
||||
const WINDOW_LABEL: &str = "splashscreen";
|
||||
const MINIMUM_DISPLAY_DURATION: Duration = Duration::from_secs(2);
|
||||
|
||||
struct SplashscreenState {
|
||||
opened_at: Instant,
|
||||
}
|
||||
|
||||
pub fn open(handle: &AppHandle) -> Result<(), String> {
|
||||
tauri::WebviewWindowBuilder::new(handle, WINDOW_LABEL, WebviewUrl::App("/splash.html".into()))
|
||||
.title("Friendolls")
|
||||
.inner_size(500.0, 290.0)
|
||||
.resizable(false)
|
||||
.minimizable(false)
|
||||
.maximizable(false)
|
||||
.decorations(false)
|
||||
.shadow(false)
|
||||
.skip_taskbar(true)
|
||||
.always_on_top(true)
|
||||
.center()
|
||||
.build()
|
||||
.map_err(|error| error.to_string())?;
|
||||
|
||||
handle.manage(SplashscreenState {
|
||||
opened_at: Instant::now(),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn close(handle: &AppHandle) -> Result<(), String> {
|
||||
let opened_at = handle.state::<SplashscreenState>().opened_at;
|
||||
tokio::time::sleep(MINIMUM_DISPLAY_DURATION.saturating_sub(opened_at.elapsed())).await;
|
||||
|
||||
if let Some(window) = handle.get_webview_window(WINDOW_LABEL) {
|
||||
window.close().map_err(|error| error.to_string())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Friendolls Splash</title>
|
||||
<script>
|
||||
document.addEventListener("contextmenu", function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body style="width: 100%; height: 100%">
|
||||
<div id="splash"></div>
|
||||
<script>
|
||||
document.getElementById("splash").style.backgroundImage =
|
||||
'url("/splash.png")';
|
||||
</script>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
}
|
||||
#splash {
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
width: 500px;
|
||||
height: 290px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 243 KiB |
Reference in New Issue
Block a user