minor refactoring of app startup sequence & some extra trivial matters
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
use crate::{
|
||||
lock_r,
|
||||
models::app_data::AppData,
|
||||
state::{init_app_data, FDOLL},
|
||||
state::{init_app_data_scoped, AppDataRefreshScope, FDOLL},
|
||||
};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_app_data() -> Result<AppData, String> {
|
||||
let guard = lock_r!(FDOLL);
|
||||
Ok(guard.ui.app_data.clone())
|
||||
Ok(guard.user_data.clone())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn refresh_app_data() -> Result<AppData, String> {
|
||||
init_app_data().await;
|
||||
init_app_data_scoped(AppDataRefreshScope::All).await;
|
||||
let guard = lock_r!(FDOLL);
|
||||
Ok(guard.ui.app_data.clone())
|
||||
Ok(guard.user_data.clone())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use tauri;
|
||||
use tracing;
|
||||
|
||||
use crate::init::lifecycle;
|
||||
use crate::{init::lifecycle::construct_user_session, services::scene::close_splash_window};
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn logout_and_restart() -> Result<(), String> {
|
||||
@@ -16,11 +16,11 @@ pub fn start_auth_flow() -> Result<(), String> {
|
||||
crate::services::auth::cancel_auth_flow();
|
||||
|
||||
crate::services::auth::init_auth_code_retrieval(|| {
|
||||
tracing::info!("Authentication successful, creating scene...");
|
||||
// Close welcome window if it's still open
|
||||
tracing::info!("Authentication successful, constructing user session...");
|
||||
crate::services::welcome::close_welcome_window();
|
||||
tauri::async_runtime::spawn(async {
|
||||
lifecycle::handle_authentication_flow().await;
|
||||
construct_user_session().await;
|
||||
close_splash_window();
|
||||
});
|
||||
})
|
||||
.map_err(|e| e.to_string())
|
||||
|
||||
@@ -8,8 +8,8 @@ pub mod interaction;
|
||||
pub mod sprite;
|
||||
pub mod user_status;
|
||||
|
||||
use crate::state::{init_app_data_scoped, AppDataRefreshScope, FDOLL};
|
||||
use crate::lock_r;
|
||||
use crate::state::{init_app_data_scoped, AppDataRefreshScope, FDOLL};
|
||||
use tauri::async_runtime;
|
||||
|
||||
/// Helper to execute a mutation operation and refresh app data scopes in the background.
|
||||
@@ -33,18 +33,21 @@ pub async fn refresh_app_data(scopes: &[AppDataRefreshScope]) {
|
||||
}
|
||||
|
||||
/// Helper to execute a mutation operation with conditional refresh.
|
||||
///
|
||||
///
|
||||
/// # Example
|
||||
/// ```ignore
|
||||
/// pub async fn delete_doll(id: String) -> Result<(), String> {
|
||||
/// let result = DollsRemote::new().delete_doll(&id).await.map_err(|e| e.to_string())?;
|
||||
/// let is_active = is_active_doll(&id);
|
||||
/// refresh_app_data_conditionally(&[AppDataRefreshScope::Dolls],
|
||||
/// refresh_app_data_conditionally(&[AppDataRefreshScope::Dolls],
|
||||
/// is_active.then_some(&[AppDataRefreshScope::User, AppDataRefreshScope::Friends]));
|
||||
/// Ok(result)
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn refresh_app_data_conditionally(base_scopes: &[AppDataRefreshScope], conditional_scopes: Option<&[AppDataRefreshScope]>) {
|
||||
pub async fn refresh_app_data_conditionally(
|
||||
base_scopes: &[AppDataRefreshScope],
|
||||
conditional_scopes: Option<&[AppDataRefreshScope]>,
|
||||
) {
|
||||
let mut all_scopes = base_scopes.to_vec();
|
||||
if let Some(extra_scopes) = conditional_scopes {
|
||||
all_scopes.extend_from_slice(extra_scopes);
|
||||
@@ -57,8 +60,7 @@ pub async fn refresh_app_data_conditionally(base_scopes: &[AppDataRefreshScope],
|
||||
pub fn is_active_doll(doll_id: &str) -> bool {
|
||||
let guard = lock_r!(FDOLL);
|
||||
guard
|
||||
.ui
|
||||
.app_data
|
||||
.user_data
|
||||
.user
|
||||
.as_ref()
|
||||
.and_then(|u| u.active_doll_id.as_ref())
|
||||
|
||||
Reference in New Issue
Block a user