style: cargo fmt --all — make codebase rustfmt-clean
Some checks failed
Build and Test / Build Server (Linux) (push) Failing after 2m59s
Build and Test / Build Agent (Windows) (push) Has started running
Build and Test / Security Audit (push) Has been cancelled
Build and Test / Build Summary (push) Has been cancelled
Run Tests / Test Server (push) Has been cancelled
Run Tests / Test Agent (push) Has been cancelled
Run Tests / Code Coverage (push) Has been cancelled
Run Tests / Lint and Format Check (push) Has been cancelled

First run of the build-and-test CI gate (cargo fmt --all -- --check) surfaced
pre-existing formatting drift across the agent and server crates. Apply rustfmt
across the workspace so the codebase meets its own CI gate. Pure formatting; no
logic changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-29 15:02:12 +00:00
parent f2e0456f8d
commit 1c5c1e78e7
48 changed files with 1174 additions and 797 deletions

View File

@@ -37,9 +37,9 @@ fn show_debug_console() {
// No-op on non-Windows platforms
}
use crate::proto::{Message, message, ChatMessage, AgentStatus, Heartbeat, HeartbeatAck};
use crate::proto::{message, AgentStatus, ChatMessage, Heartbeat, HeartbeatAck, Message};
use crate::transport::WebSocketTransport;
use crate::tray::{TrayController, TrayAction};
use crate::tray::{TrayAction, TrayController};
use anyhow::Result;
use std::time::{Duration, Instant};
@@ -71,8 +71,8 @@ pub struct SessionManager {
enum SessionState {
Disconnected,
Connecting,
Idle, // Connected but not streaming - minimal resource usage
Streaming, // Actively capturing and sending frames
Idle, // Connected but not streaming - minimal resource usage
Streaming, // Actively capturing and sending frames
}
impl SessionManager {
@@ -103,10 +103,11 @@ impl SessionManager {
&self.config.api_key,
Some(&self.hostname),
self.config.support_code.as_deref(),
).await?;
)
.await?;
self.transport = Some(transport);
self.state = SessionState::Idle; // Start in idle mode
self.state = SessionState::Idle; // Start in idle mode
tracing::info!("Connected to server, entering idle mode");
@@ -120,8 +121,12 @@ impl SessionManager {
}
tracing::info!("Initializing streaming resources...");
tracing::info!("Capture config: use_dxgi={}, gdi_fallback={}, fps={}",
self.config.capture.use_dxgi, self.config.capture.gdi_fallback, self.config.capture.fps);
tracing::info!(
"Capture config: use_dxgi={}, gdi_fallback={}, fps={}",
self.config.capture.use_dxgi,
self.config.capture.gdi_fallback,
self.config.capture.fps
);
// Get primary display with panic protection
tracing::debug!("Enumerating displays...");
@@ -132,12 +137,19 @@ impl SessionManager {
return Err(anyhow::anyhow!("Display enumeration panicked"));
}
};
tracing::info!("Using display: {} ({}x{})",
primary_display.name, primary_display.width, primary_display.height);
tracing::info!(
"Using display: {} ({}x{})",
primary_display.name,
primary_display.width,
primary_display.height
);
// Create capturer with panic protection
// Force GDI mode if DXGI fails or panics
tracing::debug!("Creating capturer (DXGI={})...", self.config.capture.use_dxgi);
tracing::debug!(
"Creating capturer (DXGI={})...",
self.config.capture.use_dxgi
);
let capturer = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
capture::create_capturer(
primary_display.clone(),
@@ -157,13 +169,13 @@ impl SessionManager {
tracing::info!("Capturer created successfully");
// Create encoder with panic protection
tracing::debug!("Creating encoder (codec={}, quality={})...",
self.config.encoding.codec, self.config.encoding.quality);
tracing::debug!(
"Creating encoder (codec={}, quality={})...",
self.config.encoding.codec,
self.config.encoding.quality
);
let encoder = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
encoder::create_encoder(
&self.config.encoding.codec,
self.config.encoding.quality,
)
encoder::create_encoder(&self.config.encoding.codec, self.config.encoding.quality)
})) {
Ok(result) => result?,
Err(e) => {
@@ -202,7 +214,9 @@ impl SessionManager {
/// Get display count for status reports
fn get_display_count(&self) -> i32 {
capture::enumerate_displays().map(|d| d.len() as i32).unwrap_or(1)
capture::enumerate_displays()
.map(|d| d.len() as i32)
.unwrap_or(1)
}
/// Send agent status to server
@@ -249,7 +263,11 @@ impl SessionManager {
}
/// Run the session main loop with tray and chat event processing
pub async fn run_with_tray(&mut self, tray: Option<&TrayController>, chat: Option<&ChatController>) -> Result<()> {
pub async fn run_with_tray(
&mut self,
tray: Option<&TrayController>,
chat: Option<&ChatController>,
) -> Result<()> {
if self.transport.is_none() {
anyhow::bail!("Not connected");
}
@@ -395,12 +413,23 @@ impl SessionManager {
}
// Periodic update check (only for persistent agents, not support sessions)
if self.config.support_code.is_none() && last_update_check.elapsed() >= UPDATE_CHECK_INTERVAL {
if self.config.support_code.is_none()
&& last_update_check.elapsed() >= UPDATE_CHECK_INTERVAL
{
last_update_check = Instant::now();
let server_url = self.config.server_url.replace("/ws/agent", "").replace("wss://", "https://").replace("ws://", "http://");
let server_url = self
.config
.server_url
.replace("/ws/agent", "")
.replace("wss://", "https://")
.replace("ws://", "http://");
match crate::update::check_for_update(&server_url).await {
Ok(Some(version_info)) => {
tracing::info!("Update available: {} -> {}", crate::build_info::VERSION, version_info.latest_version);
tracing::info!(
"Update available: {} -> {}",
crate::build_info::VERSION,
version_info.latest_version
);
if let Err(e) = crate::update::perform_update(&version_info).await {
tracing::error!("Auto-update failed: {}", e);
}
@@ -429,7 +458,9 @@ impl SessionManager {
if let Ok(encoded) = encoder.encode(&frame) {
if encoded.size > 0 {
let msg = Message {
payload: Some(message::Payload::VideoFrame(encoded.frame)),
payload: Some(message::Payload::VideoFrame(
encoded.frame,
)),
};
let transport = self.transport.as_mut().unwrap();
if let Err(e) = transport.send(msg).await {
@@ -472,26 +503,40 @@ impl SessionManager {
match msg.payload {
Some(message::Payload::MouseEvent(mouse)) => {
if let Some(input) = self.input.as_mut() {
use crate::proto::MouseEventType;
use crate::input::MouseButton;
use crate::proto::MouseEventType;
match MouseEventType::try_from(mouse.event_type).unwrap_or(MouseEventType::MouseMove) {
match MouseEventType::try_from(mouse.event_type)
.unwrap_or(MouseEventType::MouseMove)
{
MouseEventType::MouseMove => {
input.mouse_move(mouse.x, mouse.y)?;
}
MouseEventType::MouseDown => {
input.mouse_move(mouse.x, mouse.y)?;
if let Some(ref buttons) = mouse.buttons {
if buttons.left { input.mouse_click(MouseButton::Left, true)?; }
if buttons.right { input.mouse_click(MouseButton::Right, true)?; }
if buttons.middle { input.mouse_click(MouseButton::Middle, true)?; }
if buttons.left {
input.mouse_click(MouseButton::Left, true)?;
}
if buttons.right {
input.mouse_click(MouseButton::Right, true)?;
}
if buttons.middle {
input.mouse_click(MouseButton::Middle, true)?;
}
}
}
MouseEventType::MouseUp => {
if let Some(ref buttons) = mouse.buttons {
if buttons.left { input.mouse_click(MouseButton::Left, false)?; }
if buttons.right { input.mouse_click(MouseButton::Right, false)?; }
if buttons.middle { input.mouse_click(MouseButton::Middle, false)?; }
if buttons.left {
input.mouse_click(MouseButton::Left, false)?;
}
if buttons.right {
input.mouse_click(MouseButton::Right, false)?;
}
if buttons.middle {
input.mouse_click(MouseButton::Middle, false)?;
}
}
}
MouseEventType::MouseWheel => {
@@ -538,10 +583,19 @@ impl SessionManager {
tracing::info!("Update command received from server: {}", cmd.reason);
// Trigger update check and perform update if available
// The server URL is derived from the config
let server_url = self.config.server_url.replace("/ws/agent", "").replace("wss://", "https://").replace("ws://", "http://");
let server_url = self
.config
.server_url
.replace("/ws/agent", "")
.replace("wss://", "https://")
.replace("ws://", "http://");
match crate::update::check_for_update(&server_url).await {
Ok(Some(version_info)) => {
tracing::info!("Update available: {} -> {}", crate::build_info::VERSION, version_info.latest_version);
tracing::info!(
"Update available: {} -> {}",
crate::build_info::VERSION,
version_info.latest_version
);
if let Err(e) = crate::update::perform_update(&version_info).await {
tracing::error!("Update failed: {}", e);
}