cargo fmt
This commit is contained in:
@@ -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<Option<String>, String> {
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn get_friend_active_doll_sprites_base64(
|
||||
) -> Result<friends::FriendActiveDollSpritesDto, String> {
|
||||
pub fn get_friend_active_doll_sprites_base64() -> Result<friends::FriendActiveDollSpritesDto, String>
|
||||
{
|
||||
friends::sync_active_doll_sprites_from_app_data();
|
||||
Ok(friends::get_active_doll_sprites_snapshot())
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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<DollDto, Stri
|
||||
refresh_app_data_conditionally(
|
||||
&[AppDataRefreshScope::Dolls],
|
||||
is_active.then_some(&[AppDataRefreshScope::User, AppDataRefreshScope::Friends]),
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
@@ -72,7 +70,8 @@ pub async fn delete_doll(id: String) -> Result<(), String> {
|
||||
refresh_app_data_conditionally(
|
||||
&[AppDataRefreshScope::Dolls],
|
||||
is_active.then_some(&[AppDataRefreshScope::User, AppDataRefreshScope::Friends]),
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<tauri::AppHandle<tauri::Wry>> = std::sync::OnceLock::new();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"))?;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -96,7 +96,11 @@ pub async fn start_sso(provider: &str, redirect_uri: &str) -> Result<StartSsoRes
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
ensure_success(response).await?.json().await.map_err(AuthError::from)
|
||||
ensure_success(response)
|
||||
.await?
|
||||
.json()
|
||||
.await
|
||||
.map_err(AuthError::from)
|
||||
}
|
||||
|
||||
pub async fn exchange_sso_code(code: &str) -> Result<AuthPass, AuthError> {
|
||||
|
||||
@@ -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<Option<OAuthCallbackPa
|
||||
(Some("GET"), Some(path)) if path.starts_with("/callback") => {
|
||||
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> {
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,7 +12,6 @@ pub struct NetworkState {
|
||||
pub health_monitor_token: Option<tokio_util::sync::CancellationToken>,
|
||||
}
|
||||
|
||||
|
||||
pub fn init_network_state() -> NetworkState {
|
||||
let http_client = reqwest::ClientBuilder::new()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
|
||||
Reference in New Issue
Block a user