refactoring of app.rs and relevant flow files

This commit is contained in:
2026-01-25 23:10:09 +08:00
parent d1ef0a010f
commit 76943f3362
4 changed files with 49 additions and 25 deletions

View File

@@ -18,7 +18,7 @@ pub fn start_auth_flow() -> Result<(), String> {
// Close welcome window if it's still open
crate::services::welcome::close_welcome_window();
tauri::async_runtime::spawn(async {
crate::app::bootstrap().await;
crate::startup::bootstrap().await;
});
})
.map_err(|e| e.to_string())

View File

@@ -22,11 +22,12 @@ use tracing_subscriber::{self, util::SubscriberInitExt};
static APP_HANDLE: std::sync::OnceLock<tauri::AppHandle<tauri::Wry>> = std::sync::OnceLock::new();
mod app;
mod commands;
mod lifecycle;
mod models;
mod remotes;
mod services;
mod startup;
mod state;
mod system_tray;
mod utilities;
@@ -86,7 +87,7 @@ fn setup_fdoll() -> Result<(), tauri::Error> {
open_splash_window();
state::init_fdoll_state(Some(_guard));
async_runtime::spawn(async move { app::start_fdoll().await });
async_runtime::spawn(async move { lifecycle::start_fdoll().await });
Ok(())
}

View File

@@ -0,0 +1,42 @@
use crate::{
lock_w,
services::{
active_app::init_active_app_changes_listener,
health_manager::show_health_manager_with_error,
},
startup::init_startup_sequence,
state::FDOLL,
system_tray::init_system_tray,
};
/// Initializes and starts the core app lifecycle after initial setup.
///
/// This function handles:
/// - System tray initialization and storage in app state
/// - Active app change listener setup
/// - Startup sequence execution with error handling
///
/// # Errors
/// If the startup sequence fails, displays a health manager dialog
/// with the error details.
///
/// # Example
/// ```
/// // Called automatically during app setup in setup_fdoll()
/// lifecycle::start_fdoll().await;
/// ```
pub async fn start_fdoll() {
let tray = init_system_tray();
{
let mut guard = lock_w!(FDOLL);
guard.tray = Some(tray);
}
// Begin listening for foreground app changes
init_active_app_changes_listener();
if let Err(err) = init_startup_sequence().await {
tracing::warn!("Startup sequence encountered an error: {}", err);
show_health_manager_with_error(Some(err.to_string()));
}
}

View File

@@ -4,37 +4,18 @@ use tokio::time::{sleep, Instant};
use tracing::{info, warn};
use crate::{
lock_w,
models::health::HealthError,
remotes::health::HealthRemote,
services::{
active_app::init_active_app_changes_listener,
auth::{get_access_token, get_tokens},
health_manager::show_health_manager_with_error,
scene::{close_splash_window, open_scene_window, open_splash_window},
welcome::open_welcome_window,
ws::init_ws_client,
},
state::{init_app_data, FDOLL},
system_tray::{init_system_tray, update_system_tray},
state::init_app_data,
system_tray::update_system_tray,
};
pub async fn start_fdoll() {
let tray = init_system_tray();
{
let mut guard = lock_w!(FDOLL);
guard.tray = Some(tray);
}
// Begin listening for foreground app changes
init_active_app_changes_listener();
if let Err(err) = init_startup_sequence().await {
tracing::error!("startup sequence failed: {err}");
show_health_manager_with_error(Some(err.to_string()));
}
}
async fn init_ws_after_auth() {
const MAX_ATTEMPTS: u8 = 5;
const BACKOFF: Duration = Duration::from_millis(300);
@@ -90,7 +71,7 @@ pub async fn bootstrap() {
/// Perform checks for environment, network condition
/// and handle situations where startup would not be appropriate.
async fn init_startup_sequence() -> Result<(), HealthError> {
pub async fn init_startup_sequence() -> Result<(), HealthError> {
let health_remote = HealthRemote::try_new()?;
// simple retry loop to smooth transient network issues