diff --git a/src-tauri/src/proxy_server.rs b/src-tauri/src/proxy_server.rs index 008a1b3..2f15b5f 100644 --- a/src-tauri/src/proxy_server.rs +++ b/src-tauri/src/proxy_server.rs @@ -601,7 +601,7 @@ pub async fn run_proxy_server(config: ProxyConfig) -> Result<(), Box Result<(), Box 0 || requests > 0; - if has_recent_activity { + // Always flush if we have traffic, or if bytes changed, or if it's been less than 30s since activity + // This ensures traffic is always persisted, even during active periods + let should_flush = + has_traffic || bytes_changed || time_since_activity < std::time::Duration::from_secs(30); + + if should_flush { if let Err(e) = tracker.flush_to_disk() { log::error!("Failed to flush traffic stats: {}", e); } else { - last_activity_time = std::time::Instant::now(); - last_byte_count = current_bytes; + // Update tracking state after successful flush + if has_traffic || bytes_changed { + last_activity_time = std::time::Instant::now(); + } + // After flush, bytes are reset to 0, so update last_byte_count + last_byte_count = 0; } } }