diff --git a/src-tauri/src/commands/app_state.rs b/src-tauri/src/commands/app_state.rs index cb26408..94ce7e9 100644 --- a/src-tauri/src/commands/app_state.rs +++ b/src-tauri/src/commands/app_state.rs @@ -3,7 +3,9 @@ use crate::{ models::app_data::UserData, services::{ app_data::{init_app_data_scoped, AppDataRefreshScope}, - friends, presence_modules::models::ModuleMetadata, sprite, + friends, + presence_modules::models::ModuleMetadata, + sprite, }, state::FDOLL, }; @@ -38,8 +40,8 @@ pub fn get_active_doll_sprite_base64() -> Result, String> { #[tauri::command] #[specta::specta] -pub fn get_friend_active_doll_sprites_base64( -) -> Result { +pub fn get_friend_active_doll_sprites_base64() -> Result +{ friends::sync_active_doll_sprites_from_app_data(); Ok(friends::get_active_doll_sprites_snapshot()) } diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index ea549e8..691b6af 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -1,8 +1,6 @@ use crate::{ lock_w, - services::client_config::{ - load_app_config, open_config_window, save_app_config, AppConfig, - }, + services::client_config::{load_app_config, open_config_window, save_app_config, AppConfig}, state::FDOLL, }; diff --git a/src-tauri/src/commands/dolls.rs b/src-tauri/src/commands/dolls.rs index 0b7fc04..21f72a5 100644 --- a/src-tauri/src/commands/dolls.rs +++ b/src-tauri/src/commands/dolls.rs @@ -1,10 +1,7 @@ use crate::{ commands::{is_active_doll, refresh_app_data, refresh_app_data_conditionally}, models::dolls::{CreateDollDto, DollDto, UpdateDollDto}, - remotes::{ - dolls::DollsRemote, - user::UserRemote, - }, + remotes::{dolls::DollsRemote, user::UserRemote}, services::app_data::AppDataRefreshScope, }; @@ -53,7 +50,8 @@ pub async fn update_doll(id: String, dto: UpdateDollDto) -> Result Result<(), String> { refresh_app_data_conditionally( &[AppDataRefreshScope::Dolls], is_active.then_some(&[AppDataRefreshScope::User, AppDataRefreshScope::Friends]), - ).await; + ) + .await; Ok(()) } diff --git a/src-tauri/src/commands/friends.rs b/src-tauri/src/commands/friends.rs index 1da39b1..85df4d4 100644 --- a/src-tauri/src/commands/friends.rs +++ b/src-tauri/src/commands/friends.rs @@ -1,8 +1,8 @@ -use crate::remotes::friends::FriendRemote; +use crate::commands::refresh_app_data; use crate::models::friends::{ FriendRequestResponseDto, FriendshipResponseDto, SendFriendRequestDto, UserBasicDto, }; -use crate::commands::refresh_app_data; +use crate::remotes::friends::FriendRemote; use crate::services::app_data::AppDataRefreshScope; #[tauri::command] diff --git a/src-tauri/src/init/mod.rs b/src-tauri/src/init/mod.rs index 30ee1c0..1169e1e 100644 --- a/src-tauri/src/init/mod.rs +++ b/src-tauri/src/init/mod.rs @@ -1,8 +1,5 @@ use crate::{ - init::{ - lifecycle::validate_server_health, - tracing::init_logging, - }, + init::{lifecycle::validate_server_health, tracing::init_logging}, services::{ auth::get_session_token, cursor::init_cursor_tracking, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 16a65ea..2feaddd 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -27,12 +27,11 @@ use tauri::async_runtime; use tauri_specta::{collect_commands, collect_events, Builder as SpectaBuilder, ErrorHandlingMode}; use crate::services::app_events::{ - ActiveDollSpriteChanged, AppDataRefreshed, AuthFlowUpdated, CreateDoll, CursorMoved, - EditDoll, FriendActiveDollChanged, FriendActiveDollSpritesUpdated, - FriendCursorPositionsUpdated, FriendDisconnected, - FriendRequestAccepted, FriendRequestDenied, FriendRequestReceived, FriendUserStatusChanged, - InteractionDeliveryFailed, InteractionReceived, SceneInteractiveChanged, SetInteractionOverlay, - Unfriended, UserStatusChanged, + ActiveDollSpriteChanged, AppDataRefreshed, AuthFlowUpdated, CreateDoll, CursorMoved, EditDoll, + FriendActiveDollChanged, FriendActiveDollSpritesUpdated, FriendCursorPositionsUpdated, + FriendDisconnected, FriendRequestAccepted, FriendRequestDenied, FriendRequestReceived, + FriendUserStatusChanged, InteractionDeliveryFailed, InteractionReceived, + SceneInteractiveChanged, SetInteractionOverlay, Unfriended, UserStatusChanged, }; static APP_HANDLE: std::sync::OnceLock> = std::sync::OnceLock::new(); diff --git a/src-tauri/src/remotes/dolls.rs b/src-tauri/src/remotes/dolls.rs index e03ab5a..eb1664f 100644 --- a/src-tauri/src/remotes/dolls.rs +++ b/src-tauri/src/remotes/dolls.rs @@ -1,7 +1,7 @@ use reqwest::Client; -use crate::{lock_r, services::auth::with_auth, state::FDOLL, models::dolls::*}; use crate::models::remote_error::RemoteError; +use crate::{lock_r, models::dolls::*, services::auth::with_auth, state::FDOLL}; pub struct DollsRemote { pub base_url: String, @@ -19,7 +19,8 @@ impl DollsRemote { .expect("App configuration error") .clone(), client: guard - .network.clients + .network + .clients .as_ref() .expect("App configuration error") .http_client diff --git a/src-tauri/src/remotes/friends.rs b/src-tauri/src/remotes/friends.rs index 335ef0d..df84127 100644 --- a/src-tauri/src/remotes/friends.rs +++ b/src-tauri/src/remotes/friends.rs @@ -1,7 +1,7 @@ use reqwest::Client; -use crate::{lock_r, services::auth::with_auth, state::FDOLL, models::friends::*}; use crate::models::remote_error::RemoteError; +use crate::{lock_r, models::friends::*, services::auth::with_auth, state::FDOLL}; pub struct FriendRemote { pub base_url: String, @@ -19,7 +19,8 @@ impl FriendRemote { .expect("App configuration error") .clone(), client: guard - .network.clients + .network + .clients .as_ref() .expect("App configuration error") .http_client diff --git a/src-tauri/src/remotes/health.rs b/src-tauri/src/remotes/health.rs index 73c9fd3..306b495 100644 --- a/src-tauri/src/remotes/health.rs +++ b/src-tauri/src/remotes/health.rs @@ -1,6 +1,6 @@ use reqwest::Client; -use crate::{lock_r, state::FDOLL, models::health::*}; +use crate::{lock_r, models::health::*, state::FDOLL}; pub struct HealthRemote { pub base_url: String, @@ -18,7 +18,8 @@ impl HealthRemote { .ok_or(HealthError::ConfigMissing("api_base_url"))?; let client = guard - .network.clients + .network + .clients .as_ref() .map(|c| c.http_client.clone()) .ok_or(HealthError::ConfigMissing("http_client"))?; diff --git a/src-tauri/src/remotes/user.rs b/src-tauri/src/remotes/user.rs index 2dbf0cd..e3f4348 100644 --- a/src-tauri/src/remotes/user.rs +++ b/src-tauri/src/remotes/user.rs @@ -1,6 +1,6 @@ use reqwest::{Client, Error}; -use crate::{lock_r, services::auth::with_auth, state::FDOLL, models::user::*}; +use crate::{lock_r, models::user::*, services::auth::with_auth, state::FDOLL}; pub struct UserRemote { pub base_url: String, @@ -18,7 +18,8 @@ impl UserRemote { .expect("App configuration error") .clone(), client: guard - .network.clients + .network + .clients .as_ref() .expect("App configuration error") .http_client diff --git a/src-tauri/src/services/app_data/refresh.rs b/src-tauri/src/services/app_data/refresh.rs index 0252e66..72a0bb3 100644 --- a/src-tauri/src/services/app_data/refresh.rs +++ b/src-tauri/src/services/app_data/refresh.rs @@ -63,7 +63,10 @@ pub async fn init_app_data_scoped(scope: AppDataRefreshScope) { } } - if matches!(scope, AppDataRefreshScope::All | AppDataRefreshScope::Friends) { + if matches!( + scope, + AppDataRefreshScope::All | AppDataRefreshScope::Friends + ) { match friend_remote.get_friends().await { Ok(friends_list) => { let mut guard = lock_w!(FDOLL); diff --git a/src-tauri/src/services/auth/api.rs b/src-tauri/src/services/auth/api.rs index 7705c78..5c8af5f 100644 --- a/src-tauri/src/services/auth/api.rs +++ b/src-tauri/src/services/auth/api.rs @@ -96,7 +96,11 @@ pub async fn start_sso(provider: &str, redirect_uri: &str) -> Result Result { diff --git a/src-tauri/src/services/auth/flow.rs b/src-tauri/src/services/auth/flow.rs index 0e428ca..ac0526d 100644 --- a/src-tauri/src/services/auth/flow.rs +++ b/src-tauri/src/services/auth/flow.rs @@ -1,5 +1,5 @@ -use tauri_specta::Event as _; use tauri_plugin_opener::OpenerExt; +use tauri_specta::Event as _; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; use tokio_util::sync::CancellationToken; @@ -90,7 +90,9 @@ pub async fn start_browser_auth_flow(provider: &str) -> Result<(), AuthError> { if callback.params.state != expected_state { error!("SSO state mismatch"); - if let Err(err) = write_html_response(&mut callback.stream, AUTH_FAILED_HTML).await { + if let Err(err) = + write_html_response(&mut callback.stream, AUTH_FAILED_HTML).await + { warn!("Failed to write auth failure response: {}", err); } emit_auth_flow_event( @@ -109,7 +111,8 @@ pub async fn start_browser_auth_flow(provider: &str) -> Result<(), AuthError> { Err(err) => { error!("Failed to exchange SSO code: {}", err); if let Err(write_err) = - write_html_response(&mut callback.stream, AUTH_FAILED_HTML).await + write_html_response(&mut callback.stream, AUTH_FAILED_HTML) + .await { warn!("Failed to write auth failure response: {}", write_err); } @@ -127,7 +130,8 @@ pub async fn start_browser_auth_flow(provider: &str) -> Result<(), AuthError> { }; if !is_auth_flow_active(flow_id) { - let _ = write_html_response(&mut callback.stream, AUTH_CANCELLED_HTML).await; + let _ = write_html_response(&mut callback.stream, AUTH_CANCELLED_HTML) + .await; return; } @@ -182,7 +186,9 @@ pub async fn start_browser_auth_flow(provider: &str) -> Result<(), AuthError> { } else { AUTH_FAILED_HTML }; - if let Err(err) = write_html_response(&mut callback.stream, response_html).await { + if let Err(err) = + write_html_response(&mut callback.stream, response_html).await + { warn!("Failed to write auth callback response: {}", err); } emit_auth_flow_event( @@ -294,7 +300,8 @@ async fn parse_callback(stream: &mut TcpStream) -> Result { let parsed = url::Url::parse(&format!("http://localhost{}", path)) .map_err(|e| AuthError::RequestFailed(e.to_string()))?; - let params: std::collections::HashMap<_, _> = parsed.query_pairs().into_owned().collect(); + let params: std::collections::HashMap<_, _> = + parsed.query_pairs().into_owned().collect(); let state = params .get("state") @@ -372,7 +379,10 @@ fn oauth_error_message(error_code: &str, description: Option<&String>) -> String } fn is_oauth_cancellation(error_code: &str) -> bool { - matches!(error_code, "access_denied" | "user_cancelled" | "authorization_cancelled") + matches!( + error_code, + "access_denied" | "user_cancelled" | "authorization_cancelled" + ) } async fn write_html_response(stream: &mut TcpStream, html: &str) -> Result<(), AuthError> { diff --git a/src-tauri/src/services/auth/session.rs b/src-tauri/src/services/auth/session.rs index a40c7b3..c87efcb 100644 --- a/src-tauri/src/services/auth/session.rs +++ b/src-tauri/src/services/auth/session.rs @@ -1,8 +1,10 @@ -use tracing::info; use tokio::time::{timeout, Duration}; +use tracing::info; use crate::get_app_handle; -use crate::services::{scene::close_splash_window, session::construct_user_session, welcome::close_welcome_window}; +use crate::services::{ + scene::close_splash_window, session::construct_user_session, welcome::close_welcome_window, +}; use crate::state::auth::get_auth_pass_with_refresh; use crate::{lock_w, state::FDOLL}; @@ -26,7 +28,12 @@ pub async fn logout() -> Result<(), AuthError> { clear_auth_pass()?; if let Some(refresh_token) = refresh_token { - match timeout(Duration::from_secs(5), super::api::logout_remote(&refresh_token)).await { + match timeout( + Duration::from_secs(5), + super::api::logout_remote(&refresh_token), + ) + .await + { Ok(Ok(())) => {} Ok(Err(err)) => info!("Failed to revoke refresh token on server: {}", err), Err(_) => info!("Timed out while revoking refresh token on server"), diff --git a/src-tauri/src/services/cursor.rs b/src-tauri/src/services/cursor.rs index ac91b93..d596c11 100644 --- a/src-tauri/src/services/cursor.rs +++ b/src-tauri/src/services/cursor.rs @@ -7,12 +7,7 @@ use std::time::Duration; use tokio::sync::mpsc; use tracing::{debug, error, info, warn}; -use crate::{ - get_app_handle, - lock_r, - services::app_events::CursorMoved, - state::FDOLL, -}; +use crate::{get_app_handle, lock_r, services::app_events::CursorMoved, state::FDOLL}; use tauri_specta::Event as _; #[derive(Debug, Clone, Serialize, Deserialize, Type)] diff --git a/src-tauri/src/services/health_monitor.rs b/src-tauri/src/services/health_monitor.rs index 21fd961..286443e 100644 --- a/src-tauri/src/services/health_monitor.rs +++ b/src-tauri/src/services/health_monitor.rs @@ -1,9 +1,6 @@ use crate::{ - init::lifecycle::validate_server_health, - lock_w, - services::session::handle_disastrous_failure, - services::ws::client::establish_websocket_connection, - state::FDOLL, + init::lifecycle::validate_server_health, lock_w, services::session::handle_disastrous_failure, + services::ws::client::establish_websocket_connection, state::FDOLL, }; use tokio::time::{self, Duration}; use tokio_util::sync::CancellationToken; @@ -13,7 +10,7 @@ use tracing::{info, warn}; /// and attempts to recover WebSocket connection if health checks fail. pub async fn start_health_monitor() { stop_health_monitor(); - + let cancel_token = CancellationToken::new(); { let mut guard = lock_w!(FDOLL); diff --git a/src-tauri/src/services/interaction.rs b/src-tauri/src/services/interaction.rs index accff71..4e2076f 100644 --- a/src-tauri/src/services/interaction.rs +++ b/src-tauri/src/services/interaction.rs @@ -1,6 +1,9 @@ use tracing::warn; -use crate::{models::interaction::SendInteractionDto, services::ws::{ws_emit_soft, WS_EVENT}}; +use crate::{ + models::interaction::SendInteractionDto, + services::ws::{ws_emit_soft, WS_EVENT}, +}; pub async fn send_interaction(dto: SendInteractionDto) -> Result<(), String> { ws_emit_soft(WS_EVENT::CLIENT_SEND_INTERACTION, dto) diff --git a/src-tauri/src/services/ws/client.rs b/src-tauri/src/services/ws/client.rs index 83cb696..915333f 100644 --- a/src-tauri/src/services/ws/client.rs +++ b/src-tauri/src/services/ws/client.rs @@ -23,9 +23,11 @@ pub async fn establish_websocket_connection() { return; // Success } else { // Connection failed, trigger disaster recovery - crate::services::session::handle_disastrous_failure( - Some("WebSocket connection failed. Please check your network and try again.".to_string()) - ).await; + crate::services::session::handle_disastrous_failure(Some( + "WebSocket connection failed. Please check your network and try again." + .to_string(), + )) + .await; return; } } @@ -34,9 +36,10 @@ pub async fn establish_websocket_connection() { } // If we exhausted retries without valid token - crate::services::session::handle_disastrous_failure( - Some("Failed to authenticate. Please restart and sign in again.".to_string()) - ).await; + crate::services::session::handle_disastrous_failure(Some( + "Failed to authenticate. Please restart and sign in again.".to_string(), + )) + .await; } pub async fn init_ws_client() -> bool { diff --git a/src-tauri/src/state/mod.rs b/src-tauri/src/state/mod.rs index 24bc2be..f34837e 100644 --- a/src-tauri/src/state/mod.rs +++ b/src-tauri/src/state/mod.rs @@ -2,7 +2,10 @@ use crate::{ lock_w, models::app_data::UserData, - services::{app_data::update_display_dimensions_for_scene_state, presence_modules::models::ModuleMetadata}, + services::{ + app_data::update_display_dimensions_for_scene_state, + presence_modules::models::ModuleMetadata, + }, }; use std::sync::{Arc, LazyLock, RwLock}; use tauri::tray::TrayIcon; diff --git a/src-tauri/src/state/network.rs b/src-tauri/src/state/network.rs index afc8be8..977f8d2 100644 --- a/src-tauri/src/state/network.rs +++ b/src-tauri/src/state/network.rs @@ -12,7 +12,6 @@ pub struct NetworkState { pub health_monitor_token: Option, } - pub fn init_network_state() -> NetworkState { let http_client = reqwest::ClientBuilder::new() .timeout(std::time::Duration::from_secs(30))