Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: polish the initialize flow
Vanalite1ad2967b02fd
diff --git a/src-tauri/src/core/openclaw/commands.rs b/src-tauri/src/core/openclaw/commands.rsindex 0571cdb3b..a7a137dc8 100644--- a/src-tauri/src/core/openclaw/commands.rs+++ b/src-tauri/src/core/openclaw/commands.rs@@ -2024,17 +2024,33 @@ pub async fn openclaw_status(state: State<'_, OpenClawState>) -> Result<OpenClawlet running = check_gateway_responding().await;- // Determine sandbox type early — it affects how we check version & installed+ // 1. Detect sandbox first — environment may change between checks+ // (e.g. Docker Desktop started/stopped since last status call)let is_docker_sandbox = {- let sandbox_guard = state.sandbox.lock().await;+ let mut sandbox_guard = state.sandbox.lock().await;+ let mut mode = state.sandbox_mode.lock().await;++ if let crate::core::openclaw::sandbox::SandboxMode::Active { .. } = &*mode {+ if !running {+ log::info!("Gateway not responding, resetting sandbox mode to Inactive");+ *mode = crate::core::openclaw::sandbox::SandboxMode::Inactive;+ }+ }++ // Re-detect when not running or unknown — Docker may have appeared/disappeared+ if !running || sandbox_guard.is_none() {+ let detected = crate::core::openclaw::sandbox::detect_sandbox().await;+ log::debug!("Detected sandbox: {} (tier: {})", detected.name(), detected.isolation_tier());+ *sandbox_guard = Some(detected);+ }+sandbox_guard.as_ref().map(|s| s.name() == "Docker").unwrap_or(false)};+ // 2. Check installation status using the detected sandbox typelet (openclaw_version, is_installed, node_version) = if is_docker_sandbox {- // Docker sandbox: get version from `docker exec`, skip host Node.js checklet version = check_openclaw_version_docker().await;let installed = crate::core::openclaw::sandbox_docker::DockerSandbox::is_image_available().await;- // Node.js runs inside the container, not on the hostlet node_ver = if running {check_node_version_docker().await} else {@@ -2042,7 +2058,6 @@ pub async fn openclaw_status(state: State<'_, OpenClawState>) -> Result<OpenClaw};(version, installed, node_ver)} else {- // Direct process: check host npm + Node.jslet version = match check_openclaw_installed().await {Ok(v) => v,Err(_) => None,@@ -2054,41 +2069,15 @@ pub async fn openclaw_status(state: State<'_, OpenClawState>) -> Result<OpenClawlet port_check = openclaw_check_port(OPENCLAW_PORT).await;- // Get sandbox information from state+ // 3. Read sandbox info for responselet (sandbox_type, isolation_tier) = {- let mut sandbox_guard = state.sandbox.lock().await;- let mut mode = state.sandbox_mode.lock().await;-- // If state says Active but gateway stopped, reset mode (keep sandbox for tier info)- if let crate::core::openclaw::sandbox::SandboxMode::Active { .. } = &*mode {- if !running {- log::info!("Gateway not responding, resetting sandbox mode to Inactive");- *mode = crate::core::openclaw::sandbox::SandboxMode::Inactive;- }- }-- // Re-detect sandbox if not set (e.g. fresh app launch with gateway already running)- if sandbox_guard.is_none() && running {- let detected = crate::core::openclaw::sandbox::detect_sandbox().await;- log::info!("Re-detected sandbox: {} (tier: {})", detected.name(), detected.isolation_tier());- *sandbox_guard = Some(detected);- }-- match (&*sandbox_guard, &*mode) {- (Some(sandbox), crate::core::openclaw::sandbox::SandboxMode::Active { .. }) => {- (- Some(sandbox.name().to_string()),- Some(sandbox.isolation_tier().to_string()),- )- }- (Some(sandbox), _) if running => {- (Some(sandbox.name().to_string()), Some(sandbox.isolation_tier().to_string()))- }- (Some(sandbox), _) => {- // Not running but sandbox is known — still report the tier- (Some(sandbox.name().to_string()), Some(sandbox.isolation_tier().to_string()))- }- _ => (None, None),+ let sandbox_guard = state.sandbox.lock().await;+ match &*sandbox_guard {+ Some(sandbox) => (+ Some(sandbox.name().to_string()),+ Some(sandbox.isolation_tier().to_string()),+ ),+ None => (None, None),}};diff --git a/src-tauri/src/core/openclaw/sandbox_docker.rs b/src-tauri/src/core/openclaw/sandbox_docker.rsindex b5799de71..fb4c58faa 100644--- a/src-tauri/src/core/openclaw/sandbox_docker.rs+++ b/src-tauri/src/core/openclaw/sandbox_docker.rs@@ -214,29 +214,42 @@ impl DockerSandbox {};let mut stream = client.create_image(Some(options), None, None);++ // Track per-layer progress to compute aggregate percentage.+ // Docker reports current/total per layer — we sum across all layers+ // so the progress bar only moves forward.+ let mut layer_current: std::collections::HashMap<String, i64> = std::collections::HashMap::new();+ let mut layer_total: std::collections::HashMap<String, i64> = std::collections::HashMap::new();let mut last_progress_pct: u32 = 40; // Start at 40% (where installing step begins)while let Some(result) = stream.next().await {match result {Ok(info) => {- // Calculate progress from Docker's layer download info- let mut msg = String::new();- if let Some(ref status) = info.status {- msg = status.clone();+ // Update per-layer byte tracking+ if let Some(ref id) = info.id {+ if let Some(ref detail) = info.progress_detail {+ if let (Some(current), Some(total)) = (detail.current, detail.total) {+ if total > 0 {+ layer_current.insert(id.clone(), current);+ layer_total.insert(id.clone(), total);+ }+ }+ }}- // Use progress_detail to estimate percentage (40-55 range for pull)- if let Some(ref detail) = info.progress_detail {- if let (Some(current), Some(total)) = (detail.current, detail.total) {- if total > 0 {- let pct = (current as f64 / total as f64 * 15.0) as u32 + 40;- last_progress_pct = pct.min(55);- }+ // Compute aggregate progress across all layers+ let sum_current: i64 = layer_current.values().sum();+ let sum_total: i64 = layer_total.values().sum();+ if sum_total > 0 {+ let pct = (sum_current as f64 / sum_total as f64 * 15.0) as u32 + 40;+ // Only move forward — never let the bar go backward+ let clamped = pct.min(55);+ if clamped > last_progress_pct {+ last_progress_pct = clamped;}}if let Some(ref status) = info.status {- // Only emit for meaningful status changesif status.contains("Pulling") || status.contains("Downloading")|| status.contains("Extracting") || status.contains("Pull complete")|| status.contains("Already exists")@@ -244,7 +257,7 @@ impl DockerSandbox {let display_msg = if let Some(ref id) = info.id {format!("{}: {}", status, id)} else {- msg.clone()+ status.clone()};let _ = app.emit(diff --git a/web-app/src/routes/settings/remote-access.tsx b/web-app/src/routes/settings/remote-access.tsxindex 06108d6d6..ac7dabdf5 100644--- a/web-app/src/routes/settings/remote-access.tsx+++ b/web-app/src/routes/settings/remote-access.tsx@@ -16,10 +16,8 @@ import { useTranslation } from '@/i18n/react-i18next-compat'import { useEffect, useState, useCallback } from 'react'import { invoke } from '@tauri-apps/api/core'import { toast } from 'sonner'-import { setOpenClawRunningState, syncAllModelsToOpenClaw } from '@/utils/openclaw'-import { useModelProvider } from '@/hooks/useModelProvider'+import { setOpenClawRunningState } from '@/utils/openclaw'import {- IconPlugConnected,IconLoader2,IconCopy,IconExternalLink,@@ -46,7 +44,6 @@ export const Route = createFileRoute(route.settings.remote_access as any)({function RemoteAccess() {const { t } = useTranslation()const [status, setStatus] = useState<OpenClawStatus | null>(null)- const [isStarting, setIsStarting] = useState(false)const [isStopping, setIsStopping] = useState(false)const [disconnectingChannel, setDisconnectingChannel] = useState<ChannelType | null>(null)const [isTelegramWizardOpen, setIsTelegramWizardOpen] = useState(false)@@ -138,33 +135,6 @@ const [isTailscaleDialogOpen, setIsTailscaleDialogOpen] = useState(false)}}- const bulkSyncModels = useCallback(async () => {- const { providers, selectedModel } = useModelProvider.getState()- await syncAllModelsToOpenClaw(providers, selectedModel?.id)- }, [])-- const handleStart = async () => {- try {- setIsStarting(true)- await invoke('openclaw_start')- setOpenClawRunningState(true)- await bulkSyncModels()- toast.success(t('settings:remoteAccess.running'))- await fetchStatus()- } catch (error) {- const errorMsg = error instanceof Error ? error.message : String(error)- if (errorMsg.includes('Node.js')) {- toast.error(t('settings:remoteAccess.nodeRequired'))- } else if (errorMsg.includes('Port')) {- toast.error(t('settings:remoteAccess.portInUse'))- } else {- toast.error(t('settings:remoteAccess.startError'))- }- } finally {- setIsStarting(false)- }- }-const handleStop = async () => {try {setIsStopping(true)@@ -304,27 +274,19 @@ const isRunning = status?.running ?? false}actions={<div className="flex items-center gap-2">- {isInstalled ? (- isRunning ? (- <Button- variant="destructive"- size="sm"- onClick={handleStop}- disabled={isStopping}- >- {isStopping && <IconLoader2 className="animate-spin size-4" />}- {t('settings:remoteAccess.stop')}- </Button>- ) : (- <Button size="sm" onClick={handleStart} disabled={isStarting}>- {isStarting && <IconLoader2 className="animate-spin size-4" />}- {t('settings:remoteAccess.start')}- </Button>- )+ {isRunning ? (+ <Button+ variant="destructive"+ size="sm"+ onClick={handleStop}+ disabled={isStopping}+ >+ {isStopping && <IconLoader2 className="animate-spin size-4" />}+ {t('settings:remoteAccess.stop')}+ </Button>) : (- <Button variant="secondary" size="sm" onClick={() => setIsEnableDialogOpen(true)}>- <IconPlugConnected className="size-4 text-muted-foreground" />- {t('settings:remoteAccess.install')}+ <Button size="sm" onClick={() => setIsEnableDialogOpen(true)}>+ {t('settings:remoteAccess.start')}</Button>)}</div>