diff --git a/desktop/tauri/src-tauri/src/main.rs b/desktop/tauri/src-tauri/src/main.rs index a92f8a5e..17f9580c 100644 --- a/desktop/tauri/src-tauri/src/main.rs +++ b/desktop/tauri/src-tauri/src/main.rs @@ -22,7 +22,7 @@ use log::{debug, error, info, LevelFilter}; use portmaster::PortmasterExt; use tauri_plugin_log::RotationStrategy; use traymenu::setup_tray_menu; -use window::{close_splash_window, create_main_window}; +use window::{close_splash_window, create_main_window, hide_splash_window}; #[macro_use] extern crate lazy_static; @@ -77,7 +77,11 @@ impl portmaster::Handler for WsHandler { // so we don't show the splash-screen when we loose connection. self.is_first_connect = false; - if let Err(err) = close_splash_window(&self.handle) { + // The order is important. If all current windows are destroyed tauri will exit. + // First create the main ui window then destroy the splash screen. + + // Hide splash screen. Will be closed after main window is created. + if let Err(err) = hide_splash_window(&self.handle) { error!("failed to close splash window: {}", err.to_string()); } @@ -90,6 +94,11 @@ impl portmaster::Handler for WsHandler { debug!("created main window") } + // Now it is safe to destroy the splash window. + if let Err(err) = close_splash_window(&self.handle) { + error!("failed to close splash window: {}", err.to_string()); + } + let handle = self.handle.clone(); tauri::async_runtime::spawn(async move { traymenu::tray_handler(cli, handle).await; diff --git a/desktop/tauri/src-tauri/src/window.rs b/desktop/tauri/src-tauri/src/window.rs index 46ec2ef1..09483c09 100644 --- a/desktop/tauri/src-tauri/src/window.rs +++ b/desktop/tauri/src-tauri/src/window.rs @@ -98,6 +98,13 @@ pub fn close_splash_window(app: &AppHandle) -> Result<()> { return Err(tauri::Error::WindowNotFound); } +pub fn hide_splash_window(app: &AppHandle) -> Result<()> { + if let Some(window) = app.get_webview_window("splash") { + return window.hide(); + } + return Err(tauri::Error::WindowNotFound); +} + /// Opens a window for the tauri application. /// /// If the main window has already been created, it is instructed to