Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: whatsapp QR code stream to GUI
Vanalite4bc1355e5928
diff --git a/src-tauri/src/core/openclaw/commands.rs b/src-tauri/src/core/openclaw/commands.rsindex 1828815c9..29d4eab37 100644--- a/src-tauri/src/core/openclaw/commands.rs+++ b/src-tauri/src/core/openclaw/commands.rs@@ -1,12 +1,8 @@use std::process::Stdio;use std::sync::atomic::{AtomicU64, Ordering};-use base64::Engine;-use ed25519_dalek::{SigningKey, Signer};use futures::{SinkExt, StreamExt};-use rand::rngs::OsRng;use serde::{Deserialize, Serialize};-use sha2::{Sha256, Digest};use tokio::process::Command;use tokio::net::TcpStream;use tokio_tungstenite::{connect_async_with_config, tungstenite::{self, Message, http::Request}, MaybeTlsStream, WebSocketStream};@@ -26,93 +22,6 @@ fn next_request_id() -> String {REQUEST_ID_COUNTER.fetch_add(1, Ordering::SeqCst).to_string()}-/// Device keypair for Gateway authentication-struct DeviceKeypair {- signing_key: SigningKey,- device_id: String,-}--impl DeviceKeypair {- /// Load or generate device keypair- fn load_or_generate() -> Result<Self, String> {- let config_dir = get_openclaw_config_dir()?;- let keypair_path = config_dir.join("jan_device_key.json");-- if keypair_path.exists() {- // Load existing keypair- let keypair_json = std::fs::read_to_string(&keypair_path)- .map_err(|e| format!("Failed to read keypair: {}", e))?;- let keypair_data: serde_json::Value = serde_json::from_str(&keypair_json)- .map_err(|e| format!("Failed to parse keypair: {}", e))?;-- let secret_b64 = keypair_data.get("secret")- .and_then(|v| v.as_str())- .ok_or("Missing secret key")?;-- let secret_bytes = base64::engine::general_purpose::STANDARD- .decode(secret_b64)- .map_err(|e| format!("Failed to decode secret: {}", e))?;-- let secret_array: [u8; 32] = secret_bytes- .try_into()- .map_err(|_| "Invalid secret key length")?;-- let signing_key = SigningKey::from_bytes(&secret_array);- let device_id = keypair_data.get("deviceId")- .and_then(|v| v.as_str())- .unwrap_or("jan-device")- .to_string();-- Ok(Self { signing_key, device_id })- } else {- // Generate new keypair- let signing_key = SigningKey::generate(&mut OsRng);- let verifying_key = signing_key.verifying_key();-- // Create device ID as SHA256 hash of the public key bytes- // This matches OpenClaw's device ID derivation: sha256(publicKeyBytes).hex()- let pubkey_bytes = verifying_key.as_bytes();- let mut hasher = Sha256::new();- hasher.update(pubkey_bytes);- let device_id = hex::encode(hasher.finalize());-- // Save keypair- let secret_b64 = base64::engine::general_purpose::STANDARD- .encode(signing_key.as_bytes());- let public_b64 = base64::engine::general_purpose::STANDARD- .encode(pubkey_bytes);-- let keypair_data = serde_json::json!({- "deviceId": device_id,- "secret": secret_b64,- "public": public_b64,- "createdAt": chrono::Utc::now().to_rfc3339()- });-- std::fs::write(&keypair_path, serde_json::to_string_pretty(&keypair_data).unwrap())- .map_err(|e| format!("Failed to save keypair: {}", e))?;-- log::info!("Generated new device keypair: {}", device_id);-- Ok(Self { signing_key, device_id })- }- }-- /// Sign a nonce for Gateway authentication- fn sign_nonce(&self, nonce: &str) -> (String, String, i64) {- let signed_at = chrono::Utc::now().timestamp_millis();- let message = format!("{}:{}", nonce, signed_at);- let signature = self.signing_key.sign(message.as_bytes());-- let public_key_b64 = base64::engine::general_purpose::STANDARD- .encode(self.signing_key.verifying_key().as_bytes());- let signature_b64 = base64::engine::general_purpose::STANDARD- .encode(signature.to_bytes());-- (public_key_b64, signature_b64, signed_at)- }-}-/// OpenClaw Gateway WebSocket request#[derive(Debug, Serialize)]struct GatewayRequest {@@ -136,6 +45,29 @@ struct GatewayResponse {error: Option<serde_json::Value>,}+/// Get the gateway auth token from the OpenClaw config+async fn get_gateway_auth_token() -> Result<String, String> {+ let config_path = get_openclaw_config_path()?;++ if !config_path.exists() {+ return Err("OpenClaw config not found".to_string());+ }++ let config_json = std::fs::read_to_string(&config_path)+ .map_err(|e| format!("Failed to read OpenClaw config: {}", e))?;++ let config: serde_json::Value = serde_json::from_str(&config_json)+ .map_err(|e| format!("Failed to parse OpenClaw config: {}", e))?;++ config+ .get("gateway")+ .and_then(|g| g.get("auth"))+ .and_then(|a| a.get("token"))+ .and_then(|t| t.as_str())+ .map(String::from)+ .ok_or_else(|| "Gateway auth token not found in config".to_string())+}+/// Connect to OpenClaw Gateway WebSocket and perform handshake/// Uses an explicit Origin header to pass the Gateway's origin validationasync fn connect_to_gateway() -> Result<WebSocketStream<MaybeTlsStream<TcpStream>>, String> {@@ -165,9 +97,6 @@ async fn connect_to_gateway() -> Result<WebSocketStream<MaybeTlsStream<TcpStream/// Perform the Gateway handshake (connect request) with proper protocol v3async fn gateway_handshake(ws_stream: &mut WebSocketStream<MaybeTlsStream<TcpStream>>) -> Result<(), String> {- // Load or generate device keypair- let device = DeviceKeypair::load_or_generate()?;-// Wait for connect.challenge eventlet timeout = tokio::time::Duration::from_secs(5);let challenge_result = tokio::time::timeout(timeout, async {@@ -195,21 +124,24 @@ async fn gateway_handshake(ws_stream: &mut WebSocketStream<MaybeTlsStream<TcpStrErr("No challenge received".to_string())}).await;- let nonce = match challenge_result {- Ok(Ok(Some(nonce))) => nonce,- Ok(Ok(None)) => return Err("No nonce in challenge".to_string()),+ // We wait for the challenge but don't need the nonce since device auth is disabled+ match challenge_result {+ Ok(Ok(_)) => {} // Challenge received, proceedOk(Err(e)) => return Err(e),Err(_) => return Err("Handshake timeout".to_string()),};- // Sign the nonce with device keypair- let (public_key, signature, signed_at) = device.sign_nonce(&nonce);-// Send connect request following protocol v3- // Use "webchat" as client.id and client.mode since Jan acts as an operator UI client- // The client.id must be one of the recognized values in the Gateway schema:- // "cli", "webchat", "macos", "ios-node", "android-node", etc.+ // Use "openclaw-control-ui" as client.id to enable dangerouslyDisableDeviceAuth bypass+ // This client ID is recognized by the Gateway as a Control UI client, which allows+ // bypassing device identity checks when dangerouslyDisableDeviceAuth=true+ //+ // We also pass the gateway auth token to satisfy the shared auth requirementlet connect_id = next_request_id();++ // Read the gateway auth token from config+ let auth_token = get_gateway_auth_token().await.unwrap_or_default();+let connect_request = serde_json::json!({"type": "req","id": connect_id,@@ -218,33 +150,28 @@ async fn gateway_handshake(ws_stream: &mut WebSocketStream<MaybeTlsStream<TcpStr"minProtocol": 3,"maxProtocol": 3,"client": {- "id": "webchat",+ "id": "openclaw-control-ui","version": env!("CARGO_PKG_VERSION"),"platform": std::env::consts::OS,"mode": "webchat"},"role": "operator",- "scopes": ["operator.read", "operator.write", "operator.channels"],+ "scopes": ["operator.read", "operator.write", "operator.channels", "operator.admin"],"caps": ["structured-commands"],"commands": [],"permissions": {},- "auth": {},+ "auth": {+ "token": auth_token+ },"locale": "en-US",- "userAgent": format!("jan-desktop/{}", env!("CARGO_PKG_VERSION")),- "device": {- "id": device.device_id,- "publicKey": public_key,- "signature": signature,- "signedAt": signed_at,- "nonce": nonce- }+ "userAgent": format!("jan-desktop/{}", env!("CARGO_PKG_VERSION"))}});let request_json = serde_json::to_string(&connect_request).map_err(|e| format!("Failed to serialize connect request: {}", e))?;- log::info!("Sending connect handshake with device auth");+ log::info!("Sending connect handshake (device auth disabled)");log::debug!("Connect request: {}", request_json);ws_stream.send(Message::Text(request_json))@@ -395,17 +322,23 @@ pub struct OpenClawSetupResult {}/// Ensure OpenClaw is fully set up and ready for channel connections-/// This is the "1-click" setup that handles:-/// 1. Check/install OpenClaw-/// 2. Configure allowed origins for Jan-/// 3. Start the Gateway if not running-/// 4. Generate device keypair if needed-/// 5. Auto-approve device for local connections-/// 6. Test the Gateway connection+/// This is the "1-click" setup that handles everything automatically:+/// 1. Clear any stale data from previous failed attempts+/// 2. Check/install OpenClaw+/// 3. Configure Gateway with correct settings (origins, device auth bypass)+/// 4. Start the Gateway if not running+/// 5. Test the Gateway connection+/// 6. Restart Gateway if config changed#[tauri::command]pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>) -> Result<OpenClawSetupResult, String> {log::info!("Starting 1-click OpenClaw setup for channels");+ // Step 0: Clear any stale data that might cause issues+ if let Err(e) = clear_stale_openclaw_data().await {+ log::warn!("Failed to clear stale data: {}", e);+ // Non-fatal, continue+ }+// Step 1: Check if OpenClaw is installedlet openclaw_version = match check_openclaw_installed().await {Ok(Some(version)) => {@@ -457,18 +390,21 @@ pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>)}};- // Step 2: Ensure Jan's origin is in the config+ // Step 2: Ensure Gateway config has all required settingslog::info!("Configuring Gateway for Jan...");- if let Err(e) = openclaw_ensure_jan_origin().await {- log::warn!("Failed to ensure Jan origin: {}", e);- // Non-fatal, continue- }+ let config_changed = match ensure_gateway_config_for_jan().await {+ Ok(changed) => changed,+ Err(e) => {+ log::warn!("Failed to configure Gateway: {}", e);+ false+ }+ };- // Step 3: Check if Gateway is running, start if not+ // Step 3: Check if Gateway is running, start or restart if neededlet gateway_running = check_gateway_responding().await;if !gateway_running {log::info!("Gateway not running, starting...");- match openclaw_start(state).await {+ match openclaw_start(state.clone()).await {Ok(()) => {log::info!("Gateway started successfully");// Wait for gateway to be ready@@ -486,9 +422,14 @@ pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>)});}}+ } else if config_changed {+ // Gateway is running but config changed, restart to apply changes+ log::info!("Config changed, restarting Gateway...");+ let _ = restart_gateway_cli().await;+ tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;}- // Step 4: Test Gateway connection (this also generates device key if needed)+ // Step 4: Test Gateway connectionlog::info!("Testing Gateway connection...");match test_gateway_connection().await {Ok(()) => {@@ -504,63 +445,38 @@ pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>)});}Err(e) => {- // Check if it's a pairing issue- if e.contains("pairing") || e.contains("device") {- log::info!("Device pairing required, attempting auto-approve...");-- // Try to auto-approve the device- match auto_approve_device().await {- Ok(()) => {- // Retry connection- tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;- match test_gateway_connection().await {- Ok(()) => {- return Ok(OpenClawSetupResult {- success: true,- step: "complete".to_string(),- openclaw_installed: true,- gateway_running: true,- device_paired: true,- error: None,- message: Some("OpenClaw is ready for channel connections".to_string()),- });- }- Err(retry_err) => {- return Ok(OpenClawSetupResult {- success: false,- step: "connect".to_string(),- openclaw_installed: true,- gateway_running: true,- device_paired: false,- error: Some(retry_err),- message: Some("Please approve the device in OpenClaw dashboard".to_string()),- });- }- }- }- Err(approve_err) => {- log::warn!("Auto-approve failed: {}", approve_err);- return Ok(OpenClawSetupResult {- success: false,- step: "pair_device".to_string(),- openclaw_installed: true,- gateway_running: true,- device_paired: false,- error: Some(e),- message: Some("Device pairing failed. Please restart the OpenClaw Gateway and try again.".to_string()),- });- }+ log::warn!("Gateway connection failed: {}", e);++ // If connection failed, try restarting the Gateway and retrying once+ // This handles cases where the Gateway needs to reload config+ log::info!("Attempting to restart Gateway and retry connection...");+ let _ = restart_gateway_cli().await;+ tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;++ // Retry connection+ match test_gateway_connection().await {+ Ok(()) => {+ return Ok(OpenClawSetupResult {+ success: true,+ step: "complete".to_string(),+ openclaw_installed: true,+ gateway_running: true,+ device_paired: true,+ error: None,+ message: Some("OpenClaw is ready for channel connections".to_string()),+ });+ }+ Err(retry_err) => {+ return Ok(OpenClawSetupResult {+ success: false,+ step: "connect".to_string(),+ openclaw_installed: true,+ gateway_running: true,+ device_paired: false,+ error: Some(retry_err),+ message: Some("Connection failed. Please check if OpenClaw Gateway is running.".to_string()),+ });}- } else {- return Ok(OpenClawSetupResult {- success: false,- step: "connect".to_string(),- openclaw_installed: true,- gateway_running: true,- device_paired: false,- error: Some(e),- message: None,- });}}}@@ -574,64 +490,176 @@ async fn test_gateway_connection() -> Result<(), String> {Ok(())}-/// Auto-approve the latest pending device (for local connections)-/// This is called automatically - no user intervention needed-async fn auto_approve_device() -> Result<(), String> {- log::info!("Attempting to auto-approve device...");-- // Get the gateway token from config for authentication- let config_path = get_openclaw_config_path()?;- let config_json = std::fs::read_to_string(&config_path)- .map_err(|e| format!("Failed to read config: {}", e))?;- let config: serde_json::Value = serde_json::from_str(&config_json)- .map_err(|e| format!("Failed to parse config: {}", e))?;-- let token = config- .get("gateway")- .and_then(|g| g.get("auth"))- .and_then(|a| a.get("token"))- .and_then(|t| t.as_str())- .unwrap_or("");-- // Run openclaw devices approve --latest with the token- // This approves the most recent pending device request automatically- let mut args = vec!["devices", "approve", "--latest"];- if !token.is_empty() {- args.push("--token");- args.push(token);- }+/// Restart the Gateway via CLI command+async fn restart_gateway_cli() -> Result<(), String> {+ log::info!("Restarting Gateway via CLI...");let output = Command::new("openclaw")- .args(&args)+ .args(["gateway", "restart"]).stdout(Stdio::piped()).stderr(Stdio::piped()).output().await- .map_err(|e| format!("Failed to run devices approve: {}", e))?;-- let stdout = String::from_utf8_lossy(&output.stdout);- let stderr = String::from_utf8_lossy(&output.stderr);-- log::info!("Device approve output: {}", stdout);- if !stderr.is_empty() {- log::debug!("Device approve stderr: {}", stderr);- }+ .map_err(|e| format!("Failed to restart gateway: {}", e))?;if output.status.success() {- log::info!("Device auto-approved successfully");+ log::info!("Gateway restarted successfully");Ok(())} else {- // Check if there are no pending requests (which is fine - device may already be approved)- let combined = format!("{}{}", stdout, stderr);- if combined.contains("no pending") || combined.contains("No pending") || combined.contains("already") {- log::info!("No pending device requests (device may already be approved)");- Ok(())- } else {- Err(format!("Failed to approve device: {}", combined))+ let stderr = String::from_utf8_lossy(&output.stderr);+ log::warn!("Gateway restart may have failed: {}", stderr);+ // Don't fail - the gateway might still be restarting+ Ok(())+ }+}++/// Clear all stale OpenClaw data that might cause connection issues+/// This is called automatically before setup to ensure a clean state+async fn clear_stale_openclaw_data() -> Result<(), String> {+ log::info!("Clearing stale OpenClaw data for fresh setup...");++ let config_dir = get_openclaw_config_dir()?;++ // List of files that might contain stale device/auth data+ let stale_files = [+ "jan_device_key.json", // Old device keypair (no longer needed)+ "whatsapp.json", // Stale WhatsApp config from failed attempts+ ];++ for file in &stale_files {+ let file_path = config_dir.join(file);+ if file_path.exists() {+ match std::fs::remove_file(&file_path) {+ Ok(_) => log::info!("Removed stale file: {}", file),+ Err(e) => log::warn!("Failed to remove {}: {}", file, e),+ }+ }+ }++ // Also clear the whatsapp_auth directory if it exists and has issues+ let whatsapp_auth_dir = config_dir.join("whatsapp_auth");+ if whatsapp_auth_dir.exists() {+ // Check if the session files are corrupted (very small or empty)+ if let Ok(entries) = std::fs::read_dir(&whatsapp_auth_dir) {+ for entry in entries.flatten() {+ if let Ok(metadata) = entry.metadata() {+ // Remove files that are suspiciously small (likely corrupted)+ if metadata.len() < 10 {+ let _ = std::fs::remove_file(entry.path());+ log::info!("Removed potentially corrupted file: {:?}", entry.path());+ }+ }+ }+ }+ }++ log::info!("Stale data cleanup complete");+ Ok(())+}++/// Ensure the Gateway config has all required settings for Jan+/// This fixes common configuration issues that cause connection failures+async fn ensure_gateway_config_for_jan() -> Result<bool, String> {+ log::info!("Ensuring Gateway config is correct for Jan...");++ let config_path = get_openclaw_config_path()?;++ if !config_path.exists() {+ log::info!("No OpenClaw config exists yet");+ return Ok(false);+ }++ let config_json = std::fs::read_to_string(&config_path)+ .map_err(|e| format!("Failed to read OpenClaw config: {}", e))?;++ let mut config: serde_json::Value = serde_json::from_str(&config_json)+ .map_err(|e| format!("Failed to parse OpenClaw config: {}", e))?;++ let mut modified = false;++ // Ensure gateway object exists+ if config.get("gateway").is_none() {+ config["gateway"] = serde_json::json!({});+ modified = true;+ }++ // Ensure gateway.controlUi object exists+ if config["gateway"].get("controlUi").is_none() {+ config["gateway"]["controlUi"] = serde_json::json!({});+ modified = true;+ }++ // 1. Ensure allowedOrigins contains Jan's origins+ let allowed_origins = config["gateway"]["controlUi"]+ .get("allowedOrigins")+ .and_then(|v| v.as_array())+ .cloned()+ .unwrap_or_default();++ let existing_origins: std::collections::HashSet<String> = allowed_origins+ .iter()+ .filter_map(|v| v.as_str())+ .map(String::from)+ .collect();++ let mut new_origins: Vec<serde_json::Value> = allowed_origins;+ for origin in JAN_ALLOWED_ORIGINS {+ if !existing_origins.contains(*origin) {+ new_origins.push(serde_json::json!(origin));+ modified = true;+ log::info!("Adding Jan origin: {}", origin);}}+ if modified {+ config["gateway"]["controlUi"]["allowedOrigins"] = serde_json::Value::Array(new_origins);+ }++ // 2. Enable dangerouslyDisableDeviceAuth for local connections+ // This is the key setting that allows connections without complex device signing+ let disable_device_auth = config["gateway"]["controlUi"]+ .get("dangerouslyDisableDeviceAuth")+ .and_then(|v| v.as_bool())+ .unwrap_or(false);++ if !disable_device_auth {+ config["gateway"]["controlUi"]["dangerouslyDisableDeviceAuth"] = serde_json::json!(true);+ modified = true;+ log::info!("Enabled dangerouslyDisableDeviceAuth for local connections");+ }++ // 3. Enable whatsapp plugin if not already+ if config.get("plugins").is_none() {+ config["plugins"] = serde_json::json!({"entries": {}});+ }+ if config["plugins"].get("entries").is_none() {+ config["plugins"]["entries"] = serde_json::json!({});+ }+ let whatsapp_enabled = config["plugins"]["entries"]+ .get("whatsapp")+ .and_then(|w| w.get("enabled"))+ .and_then(|e| e.as_bool())+ .unwrap_or(false);++ if !whatsapp_enabled {+ config["plugins"]["entries"]["whatsapp"] = serde_json::json!({"enabled": true});+ modified = true;+ log::info!("Enabled WhatsApp plugin");+ }++ if modified {+ let updated_json = serde_json::to_string_pretty(&config)+ .map_err(|e| format!("Failed to serialize config: {}", e))?;++ std::fs::write(&config_path, updated_json)+ .map_err(|e| format!("Failed to write config: {}", e))?;++ log::info!("OpenClaw config updated for Jan");+ }++ Ok(modified)}+/// Check if Node.js is installed and meets version requirements#[tauri::command]pub async fn openclaw_check_dependencies() -> NodeCheckResult {@@ -927,6 +955,20 @@ pub async fn openclaw_ensure_jan_origin() -> Result<bool, String> {}}+ // Also enable dangerouslyDisableDeviceAuth for local connections+ // This simplifies the connection flow for non-tech users+ // Security note: This is safe for loopback-only gateways (local use)+ let disable_device_auth = config["gateway"]["controlUi"]+ .get("dangerouslyDisableDeviceAuth")+ .and_then(|v| v.as_bool())+ .unwrap_or(false);++ if !disable_device_auth {+ config["gateway"]["controlUi"]["dangerouslyDisableDeviceAuth"] = serde_json::json!(true);+ modified = true;+ log::info!("Enabled dangerouslyDisableDeviceAuth for local connections");+ }+if modified {// Update the config with new originsconfig["gateway"]["controlUi"]["allowedOrigins"] = serde_json::Value::Array(new_origins);@@ -938,9 +980,9 @@ pub async fn openclaw_ensure_jan_origin() -> Result<bool, String> {std::fs::write(&config_path, updated_json).map_err(|e| format!("Failed to write config: {}", e))?;- log::info!("OpenClaw config updated with Jan's allowed origins");+ log::info!("OpenClaw config updated with Jan's allowed origins and device auth disabled");} else {- log::info!("Jan's origins already present in OpenClaw config");+ log::info!("Jan's config already correct");}Ok(modified)@@ -1982,7 +2024,48 @@ pub async fn whatsapp_start_auth(state: tauri::State<'_, OpenClawState>) -> Resu});}- log::info!("OpenClaw setup complete, proceeding with WhatsApp configuration");+ log::info!("OpenClaw setup complete, checking if WhatsApp is already linked...");++ // Step 2: Check if WhatsApp is already linked (authenticated with a phone)+ // If so, we don't need to show QR code+ let params = serde_json::json!({+ "probe": false,+ "timeoutMs": 5000+ });++ if let Ok(status) = gateway_request("channels.status", params).await {+ if let Some(channels) = status.get("channels") {+ if let Some(whatsapp) = channels.get("whatsapp") {+ let linked = whatsapp.get("linked")+ .and_then(|v| v.as_bool())+ .unwrap_or(false);+ let connected = whatsapp.get("connected")+ .and_then(|v| v.as_bool())+ .unwrap_or(false);++ if linked {+ log::info!("WhatsApp is already linked to a phone");++ // Update local config to reflect linked status+ update_whatsapp_connected_status(true).await.ok();++ return Ok(WhatsAppAuthStatus {+ in_progress: false,+ qr_code_ready: false,+ qr_code: None,+ authenticated: true,+ error: None,+ });+ }++ if connected {+ log::info!("WhatsApp is connected but not yet linked, need QR code");+ }+ }+ }+ }++ log::info!("WhatsApp not linked, proceeding with QR code setup");// Get the WhatsApp session/auth directorylet config_dir = get_openclaw_config_dir()?;@@ -2037,85 +2120,85 @@ pub async fn whatsapp_start_auth(state: tauri::State<'_, OpenClawState>) -> Resu}}- // Now try to initiate login to get QR code- // This may output QR code to terminal or start interactive session- let login_output = Command::new("openclaw")- .args([- "channels",- "login",- "--channel", "whatsapp",- "--account", "default",- ])- .stdout(Stdio::piped())- .stderr(Stdio::piped())- .output()- .await- .map_err(|e| format!("Failed to run openclaw channels login: {}", e))?;-- let login_stderr = String::from_utf8_lossy(&login_output.stderr);- let login_stdout = String::from_utf8_lossy(&login_output.stdout);-- log::info!("OpenClaw channels login output: {}", login_stdout);- if !login_stderr.is_empty() {- log::info!("OpenClaw channels login stderr: {}", login_stderr);- }+ // Now get QR code via Gateway RPC (web.login.start)+ // This returns the QR as a base64 PNG data URL that can be displayed in the UI+ log::info!("Requesting QR code via Gateway RPC...");- // Save state to local config- let whatsapp_config = WhatsAppConfig {- account_id: "default".to_string(),- session_path: auth_dir.to_string_lossy().to_string(),- connected: false,- phone_number: None,- qr_code: None, // QR code will be fetched separately or displayed in terminal- contacts_count: 0,- };+ let qr_params = serde_json::json!({+ "accountId": "default",+ "timeoutMs": 60000,+ "force": true+ });- let config_path = get_whatsapp_config_path()?;- std::fs::write(- &config_path,- serde_json::to_string_pretty(&whatsapp_config).unwrap()- ).map_err(|e| format!("Failed to save WhatsApp config: {}", e))?;+ match gateway_request("web.login.start", qr_params).await {+ Ok(qr_payload) => {+ let qr_code = qr_payload.get("qrDataUrl")+ .and_then(|v| v.as_str())+ .map(String::from);++ if qr_code.is_some() {+ log::info!("QR code received successfully");++ // Save state to local config+ let whatsapp_config = WhatsAppConfig {+ account_id: "default".to_string(),+ session_path: auth_dir.to_string_lossy().to_string(),+ connected: false,+ phone_number: None,+ qr_code: qr_code.clone(),+ contacts_count: 0,+ };++ let config_path = get_whatsapp_config_path()?;+ std::fs::write(+ &config_path,+ serde_json::to_string_pretty(&whatsapp_config).unwrap()+ ).map_err(|e| format!("Failed to save WhatsApp config: {}", e))?;++ return Ok(WhatsAppAuthStatus {+ in_progress: true,+ qr_code_ready: true,+ qr_code,+ authenticated: false,+ error: None,+ });+ } else {+ log::warn!("QR code response missing qrDataUrl");+ return Ok(WhatsAppAuthStatus {+ in_progress: false,+ qr_code_ready: false,+ qr_code: None,+ authenticated: false,+ error: Some("QR code generation failed - missing qrDataUrl".to_string()),+ });+ }+ }+ Err(e) => {+ log::error!("Failed to get QR code: {}", e);- // Check login result- if !login_output.status.success() {- // Check for specific error messages- let combined_output = format!("{}{}", login_stdout, login_stderr);+ // Check for specific error messages+ if e.contains("Unsupported channel") || e.contains("web login provider is not available") {+ return Ok(WhatsAppAuthStatus {+ in_progress: false,+ qr_code_ready: false,+ qr_code: None,+ authenticated: false,+ error: Some(+ "WhatsApp channel is not yet supported in this version of OpenClaw. \+ Please check for OpenClaw updates.".to_string()+ ),+ });+ }- if combined_output.contains("Unsupported channel") {return Ok(WhatsAppAuthStatus {in_progress: false,qr_code_ready: false,qr_code: None,authenticated: false,- error: Some(- "WhatsApp channel is not yet supported in this version of OpenClaw. \- Currently only iMessage is available. Please check for OpenClaw updates \- or consider using Telegram which may be supported.".to_string()- ),+ error: Some(format!("Failed to get QR code: {}", e)),});}-- return Ok(WhatsAppAuthStatus {- in_progress: false,- qr_code_ready: false,- qr_code: None,- authenticated: false,- error: Some(format!(- "WhatsApp login failed: {}",- if !login_stderr.is_empty() { login_stderr.to_string() } else { login_stdout.to_string() }- )),- });}-- // Login command succeeded - WhatsApp is being set up- // Note: The actual QR code may be displayed in terminal or via Gateway events- Ok(WhatsAppAuthStatus {- in_progress: true,- qr_code_ready: false,- qr_code: None,- authenticated: false,- error: None,- })}/// Get the QR code for WhatsApp authentication@@ -2145,15 +2228,19 @@ pub async fn whatsapp_get_qr_code() -> Result<WhatsAppAuthStatus, String> {Ok(payload) => {log::debug!("Channel status response: {:?}", payload);- // Check if WhatsApp channel is connected+ // Check if WhatsApp channel is linked (authenticated) or connectedif let Some(channels) = payload.get("channels") {if let Some(whatsapp) = channels.get("whatsapp") {let connected = whatsapp.get("connected").and_then(|v| v.as_bool()).unwrap_or(false);+ let linked = whatsapp.get("linked")+ .and_then(|v| v.as_bool())+ .unwrap_or(false);- if connected {- // Update local config+ // If linked, WhatsApp is already authenticated - no QR needed+ if linked {+ log::info!("WhatsApp is already linked, no QR code needed");update_whatsapp_connected_status(true).await?;return Ok(WhatsAppAuthStatus {@@ -2164,10 +2251,14 @@ pub async fn whatsapp_get_qr_code() -> Result<WhatsAppAuthStatus, String> {error: None,});}++ if connected && !linked {+ log::info!("WhatsApp connected but not linked, need to get QR code");+ }}}- // If not connected, try to get/refresh QR code+ // If not linked, try to get/refresh QR codelet qr_params = serde_json::json!({"accountId": "default","timeoutMs": 30000@@ -2301,7 +2392,7 @@ pub async fn whatsapp_check_auth() -> Result<WhatsAppAuthStatus, String> {Ok(payload) => {log::debug!("Channel status response: {:?}", payload);- // Check if WhatsApp channel is connected+ // Check if WhatsApp channel is connected or linkedif let Some(channels) = payload.get("channels") {if let Some(whatsapp) = channels.get("whatsapp") {let connected = whatsapp.get("connected")@@ -2312,8 +2403,11 @@ pub async fn whatsapp_check_auth() -> Result<WhatsAppAuthStatus, String> {.and_then(|v| v.as_bool()).unwrap_or(false);- if connected {- // Successfully authenticated+ // If linked, WhatsApp is authenticated (even if not currently connected)+ // "linked" means the account is paired with a phone+ // "connected" means the WebSocket is currently active+ if linked {+ log::info!("WhatsApp is linked (authenticated)");update_whatsapp_connected_status(true).await?;return Ok(WhatsAppAuthStatus {@@ -2325,6 +2419,11 @@ pub async fn whatsapp_check_auth() -> Result<WhatsAppAuthStatus, String> {});}+ if connected && !linked {+ // Connected but not linked - waiting for QR scan+ log::info!("WhatsApp connected but waiting for QR scan");+ }+// Check for errorslet last_error = whatsapp.get("lastError").and_then(|v| v.as_str())diff --git a/web-app/src/containers/dialogs/WhatsAppWizardDialog.tsx b/web-app/src/containers/dialogs/WhatsAppWizardDialog.tsxindex ed47b9d7e..e5626939f 100644--- a/web-app/src/containers/dialogs/WhatsAppWizardDialog.tsx+++ b/web-app/src/containers/dialogs/WhatsAppWizardDialog.tsx@@ -120,6 +120,21 @@ export function WhatsAppWizardDialog({return}+ // Check if already authenticated (WhatsApp was already linked)+ if (status.authenticated) {+ // Get the final config+ const whatsappConfig = await invoke<WhatsAppConfig>('whatsapp_get_config')+ setConfig(whatsappConfig)+ setStep('success')+ onConnected(whatsappConfig)+ return+ }++ // Check if QR code is already available in the response+ if (status.qr_code) {+ setQrCodeImage(status.qr_code)+ }+// Move to scanning stepsetStep('scanning')startPolling()diff --git a/web-app/src/locales/cs/common.json b/web-app/src/locales/cs/common.jsonindex 52649b492..3b1d52210 100644--- a/web-app/src/locales/cs/common.json+++ b/web-app/src/locales/cs/common.json@@ -46,6 +46,7 @@"copy": "Kopírovat","back": "Zpět","close": "Zavřít",+ "done": "Hotovo","next": "Další","finish": "Dokončit","skip": "Přeskočit",diff --git a/web-app/src/locales/de-DE/common.json b/web-app/src/locales/de-DE/common.jsonindex a158719cc..57d43f301 100644--- a/web-app/src/locales/de-DE/common.json+++ b/web-app/src/locales/de-DE/common.json@@ -45,6 +45,7 @@"copy": "Kopieren","back": "Zurück","close": "Schließen",+ "done": "Fertig","next": "Nächster","finish": "Abschließen","skip": "Überspringen",diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.jsonindex 4d147bd93..b93a07eb2 100644--- a/web-app/src/locales/en/common.json+++ b/web-app/src/locales/en/common.json@@ -52,6 +52,7 @@"copy": "Copy","back": "Back","close": "Close",+ "done": "Done","next": "Next","finish": "Finish","skip": "Skip",diff --git a/web-app/src/locales/en/settings.json b/web-app/src/locales/en/settings.jsonindex 8261550fc..9fc0209c8 100644--- a/web-app/src/locales/en/settings.json+++ b/web-app/src/locales/en/settings.json@@ -317,7 +317,7 @@"updateSuccess": "Llamacpp updated successfully","updateError": "Failed to update Llamacpp"},- "backendInstallSuccess": "Backend installed successfully",+ "backendInstallSuccess": "OpenClaw installed successfully!","backendInstallError": "Failed to install backend","remoteAccess": {"title": "Remote Access",@@ -326,9 +326,9 @@"enabled": "Remote Access Enabled","disabled": "Remote Access Disabled","notInstalled": "Not Installed",- "running": "Running",- "stopped": "Stopped",- "urlCopied": "URL copied to clipboard",+ "running": "Remote Access is now running",+ "stopped": "Remote Access has been stopped",+ "urlCopied": "Link copied to clipboard","activeChannels": "Active Channels","connectedUsers": "Connected Users","port": "Port",@@ -355,11 +355,11 @@"stop": "Stop","starting": "Starting...","stopping": "Stopping...",- "installError": "Failed to install OpenClaw",- "startError": "Failed to start Remote Access",- "stopError": "Failed to stop Remote Access",- "nodeRequired": "Node.js is required to run Remote Access",- "portInUse": "Port is already in use",+ "installError": "Installation failed. Please check your Node.js installation.",+ "startError": "Couldn't start Remote Access. Please try again.",+ "stopError": "Couldn't stop Remote Access. Please try again.",+ "nodeRequired": "Node.js 22+ is required. Please install it first.",+ "portInUse": "Port 18789 is in use. Please close other apps using it.","telegram": "Telegram","whatsapp": "WhatsApp","discord": "Discord",@@ -395,7 +395,7 @@"manage": "Manage","disconnect": "Disconnect","channelDisconnected": "{{channel}} disconnected",- "disconnectError": "Failed to disconnect channel",+ "disconnectError": "Couldn't disconnect. Please try again.","channelNotConnected": "Click settings to connect {{channel}}","copiedToClipboard": "Copied to clipboard","securitySettings": {diff --git a/web-app/src/locales/fr/common.json b/web-app/src/locales/fr/common.jsonindex 5ae0da3a0..7951bdb60 100644--- a/web-app/src/locales/fr/common.json+++ b/web-app/src/locales/fr/common.json@@ -46,6 +46,7 @@"copy": "Copier","back": "Retour","close": "Fermer",+ "done": "Terminé","next": "Suivant","finish": "Terminer","skip": "Passer",diff --git a/web-app/src/locales/id/common.json b/web-app/src/locales/id/common.jsonindex eaabc1ab6..2f8f55802 100644--- a/web-app/src/locales/id/common.json+++ b/web-app/src/locales/id/common.json@@ -45,6 +45,7 @@"copy": "Salin","back": "Kembali","close": "Tutup",+ "done": "Selesai","next": "Berikutnya","finish": "Selesai","skip": "Lewati",diff --git a/web-app/src/locales/ja/common.json b/web-app/src/locales/ja/common.jsonindex 235c18735..3de50157d 100644--- a/web-app/src/locales/ja/common.json+++ b/web-app/src/locales/ja/common.json@@ -45,6 +45,7 @@"copy": "コピー","back": "戻る","close": "閉じる",+ "done": "完了","next": "次へ","finish": "完了","skip": "スキップ",diff --git a/web-app/src/locales/pl/common.json b/web-app/src/locales/pl/common.jsonindex 7c232417d..d185cdf62 100644--- a/web-app/src/locales/pl/common.json+++ b/web-app/src/locales/pl/common.json@@ -45,6 +45,7 @@"copy": "Skopiuj","back": "Wstecz","close": "Zamknij",+ "done": "Gotowe","next": "Dalej","finish": "Zakończ","skip": "Pomiń",diff --git a/web-app/src/locales/pt-BR/common.json b/web-app/src/locales/pt-BR/common.jsonindex a84ff4c19..7e1f186bf 100644--- a/web-app/src/locales/pt-BR/common.json+++ b/web-app/src/locales/pt-BR/common.json@@ -46,6 +46,7 @@"copy": "Copiar","back": "Voltar","close": "Fechar",+ "done": "Concluído","next": "Próximo","finish": "Finalizar","skip": "Pular",diff --git a/web-app/src/locales/ru/common.json b/web-app/src/locales/ru/common.jsonindex 1160818eb..1293b1f05 100644--- a/web-app/src/locales/ru/common.json+++ b/web-app/src/locales/ru/common.json@@ -46,6 +46,7 @@"copy": "Копировать","back": "Назад","close": "Закрыть",+ "done": "Готово","next": "Далее","finish": "Готово","skip": "Пропустить",diff --git a/web-app/src/locales/vn/common.json b/web-app/src/locales/vn/common.jsonindex 2630fdecf..0e74bfc65 100644--- a/web-app/src/locales/vn/common.json+++ b/web-app/src/locales/vn/common.json@@ -45,6 +45,7 @@"copy": "Sao chép","back": "Quay lại","close": "Đóng",+ "done": "Hoàn tất","next": "Tiếp theo","finish": "Hoàn thành","skip": "Bỏ qua",diff --git a/web-app/src/locales/zh-CN/common.json b/web-app/src/locales/zh-CN/common.jsonindex a4c8c89f5..600bd232a 100644--- a/web-app/src/locales/zh-CN/common.json+++ b/web-app/src/locales/zh-CN/common.json@@ -45,6 +45,7 @@"copy": "复制","back": "返回","close": "关闭",+ "done": "完成","next": "下一步","finish": "完成","skip": "跳过",diff --git a/web-app/src/locales/zh-TW/common.json b/web-app/src/locales/zh-TW/common.jsonindex 667e688cc..ec7f007a4 100644--- a/web-app/src/locales/zh-TW/common.json+++ b/web-app/src/locales/zh-TW/common.json@@ -45,6 +45,7 @@"copy": "複製","back": "返回","close": "關閉",+ "done": "完成","next": "下一步","finish": "完成","skip": "略過",