From 1517152a19ee7738a17cc6b79f6f54e32121a630 Mon Sep 17 00:00:00 2001 From: hfshfg <38004547@qq.com> Date: Sat, 20 Jun 2026 12:16:42 +0800 Subject: [PATCH] fix(portable): keep config center visible on startup --- portable/Config.html | 8 +- portable/Mac-Start.command | 24 ++---- portable/Windows-Start.bat | 51 +++++------ portable/config-server/public/index.html | 17 ++-- portable/lib/loading.html | 105 ++++++++++++++++++----- portable/lib/wait-gateway.bat | 15 ++-- tests/windows-launchers.test.mjs | 35 ++++++++ 7 files changed, 164 insertions(+), 91 deletions(-) diff --git a/portable/Config.html b/portable/Config.html index 4de04d9..fcb4a20 100644 --- a/portable/Config.html +++ b/portable/Config.html @@ -168,7 +168,7 @@ input:focus { border-color: #ff6b35; }

虾盘云 首选中转站

一个 Key 用 DeepSeek / Claude / GPT / 通义 等国内外全部大模型,无需翻墙

- → 注册并获取 API Key + → 注册 / 充值 / 获取 API Key
@@ -255,7 +255,7 @@ input:focus { border-color: #ff6b35; }

请填写对应模型的 API Key

-

📌 如何获取 API Key?

+

📌 获取 / 充值 API Key

@@ -477,7 +477,7 @@ function setupStep2() { linksDiv.innerHTML = ''; if (buyLink) { linksDiv.innerHTML = ` - 🔑 ${name} — 获取 API Key + 🔑 ${name} — ${buyLink.dataset.actionLabel || '获取 API Key'} `; } // Add common alternatives @@ -498,7 +498,7 @@ function togglePw() { function buildOpenClawConfig(provider, base, model, apiKey) { // Base config that OpenClaw expects const baseConfig = { - gateway: { auth: { mode: 'token', token: 'uclaw', scopes: ['operator.admin'] } }, + gateway: { auth: { mode: 'token', token: 'uclaw', scopes: ['operator.admin'] }, remote: { token: 'uclaw' } }, commands: { native: 'auto', nativeSkills: 'auto', restart: true, ownerDisplay: 'raw' }, meta: { lastTouchedVersion: '2026.3.13', lastTouchedAt: new Date().toISOString() } }; diff --git a/portable/Mac-Start.command b/portable/Mac-Start.command index 9d25864..a1ad5e4 100755 --- a/portable/Mac-Start.command +++ b/portable/Mac-Start.command @@ -166,35 +166,23 @@ OPENCLAW_MJS="$CORE_DIR/node_modules/openclaw/openclaw.mjs" "$NODE_BIN" "$OPENCLAW_MJS" gateway run --allow-unconfigured --force --port $PORT & GW_PID=$! -# ---- 11. 是否已配置模型?openclaw.json 含 "providers" 即视为已配置 (issue #24) ---- -# 已配置:只开 Dashboard,不再每次弹配置页。未配置(首次):开 Config Center 引导填 Key。 -MODEL_CONFIGURED=0 -if grep -q '"providers"' "$CONFIG_FILE" 2>/dev/null; then - MODEL_CONFIGURED=1 -fi - -# ---- 12. 立刻打开"启动首屏",给用户即时反馈(移植自 4.0 splash)---- -# 首屏 loading.html 自己轮询 /ready,gateway 真就绪后自动跳 Dashboard——天然解决 -# "gateway 没起就开 Dashboard 拒连"的问题(同 Windows issue #46/#48)。 +# ---- 11. 立刻打开"启动首屏",给用户即时反馈(移植自 4.0 splash)---- +# 首屏 loading.html 自己轮询 /ready,就绪后停在选择页,不再自动冲进 Dashboard。 echo -e " ${YELLOW}首次启动需准备运行环境,约 30-90 秒,请稍候...${NC}" # 用 file:// URL 确保 query string(?port=)能传给浏览器;裸路径 open 会把整串当文件名。 open "file://$UCLAW_DIR/lib/loading.html?port=$PORT&token=uclaw" 2>/dev/null || true -# 首次未配置:再开 Config Center 引导填 Key -if [ "$MODEL_CONFIGURED" != "1" ]; then - open "http://127.0.0.1:18788/" 2>/dev/null || true -fi +# 每次都打开 Config Center,方便改模型、充值/获取 Key、连接微信等渠道。 +open "http://127.0.0.1:18788/" 2>/dev/null || true -# ---- 12b. gateway 首轮预热(后台、静默、非阻塞)---- +# ---- 11b. gateway 首轮预热(后台、静默、非阻塞)---- # 就绪后先唤醒 config/model 子系统,用户首次点发送时不再等。移植自 4.0 first-turn-prewarm。 "$NODE_BIN" "$UCLAW_DIR/lib/prewarm.mjs" "$PORT" uclaw >/dev/null 2>&1 & -# ---- 12c. 兜底:万一首屏页的 file:// fetch 被浏览器拦,仍轮询端口后开 Dashboard ---- +# ---- 11c. 兜底:万一首屏页的 file:// fetch 被浏览器拦,仍静默轮询端口 ---- # 慢盘首启可达 90s+,轮询上限覆盖这段。最多 ~3 分钟(180×1s)。 ( for i in $(seq 1 180); do if curl -s -o /dev/null "http://127.0.0.1:$PORT/" 2>/dev/null; then - # 首屏页通常已自己跳转;这里仅作兜底,open 同一 URL 浏览器会复用已有标签。 - [ "$MODEL_CONFIGURED" = "1" ] && open "http://127.0.0.1:$PORT/#token=uclaw" 2>/dev/null || true exit 0 fi sleep 1 diff --git a/portable/Windows-Start.bat b/portable/Windows-Start.bat index 94d7cfd..7790045 100644 --- a/portable/Windows-Start.bat +++ b/portable/Windows-Start.bat @@ -49,11 +49,11 @@ if not exist "%DATA_DIR%\memory" mkdir "%DATA_DIR%\memory" if not exist "%DATA_DIR%\backups" mkdir "%DATA_DIR%\backups" if not exist "%DATA_DIR%\logs" mkdir "%DATA_DIR%\logs" -REM ── 加速:把"重 IO、可重建"的缓存从 U 盘搬到本机硬盘 ────────────────── -REM portable-cache.mjs 算出本机缓存目录(%LOCALAPPDATA%\U-Claw\slot,UUID 隔离, -REM 换盘符仍复用),并把 .openclaw\browser 做成 junction 指向本机盘。 -REM 浏览器 user-data(几百 MB 随机小写)和 V8 编译缓存因此落本机 SSD,不再拖慢 U 盘。 -REM 静默失败:取不到就跳过,缓存留 U 盘,照常启动。 +REM Startup cache acceleration. +REM portable-cache.mjs chooses a local-disk cache slot and redirects +REM .openclaw\browser there with a junction when possible. +REM Browser user data and V8 compile cache stay off the USB drive. +REM If this fails, startup continues with the cache on the USB drive. for /f "usebackq tokens=1,* delims==" %%a in (`""%NODE_BIN%" "%UCLAW_DIR%lib\portable-cache.mjs" "%STATE_DIR%" "%UCLAW_DIR%" 2^>nul"`) do ( if "%%a"=="UCLAW_COMPILE_CACHE_DIR" set "NODE_COMPILE_CACHE=%%b" if "%%a"=="UCLAW_CACHE_ROOT" set "UCLAW_CACHE_ROOT=%%b" @@ -89,7 +89,7 @@ if not exist "%CORE_DIR%\node_modules" ( echo File system: NTFS recommended. exFAT/FAT32 will be very slow. echo. cd /d "%CORE_DIR%" - REM 把 npm 缓存留在盘内,避免污染系统 %APPDATA%\npm-cache(拔盘不留痕) + REM Keep npm cache inside the portable app instead of system APPDATA. set "npm_config_cache=%APP_DIR%\.npm-cache" call "%NPM_BIN%" install --registry=https://registry.npmmirror.com --ignore-scripts --no-audit --no-fund --omit=dev echo. @@ -144,9 +144,9 @@ echo Starting Config Center on port 18788... set "CONFIG_SERVER=%UCLAW_DIR%config-server" start /B "" "%NODE_BIN%" "%CONFIG_SERVER%\server.js" >nul 2>&1 -REM 等 Config Server 就绪 —— 动态探测而非写死等待。 -REM 它通常 <1s 就起来,写死 timeout /t 2 是白等。改为每 ~0.3s 探测 18788, -REM 最多 ~6s(20 次)兜底。监听到就立刻往下走。 +REM Wait for Config Server with polling instead of a fixed delay. +REM It is usually ready in under one second. Poll about every 0.3 seconds, +REM up to about 6 seconds, then continue anyway. set /a CFG_TRIES=0 :wait_config netstat -an | findstr ":18788 " | findstr "LISTENING" >nul 2>&1 @@ -157,36 +157,25 @@ ping -n 1 -w 300 127.0.0.1 >nul 2>&1 goto :wait_config :config_ready -REM IMPORTANT: 不要在 gateway 启动前就开 Dashboard 浏览器! -REM 慢 U 盘上 OpenClaw 首次启动要 staging bundled deps(几十秒), -REM 过早打开 http://127.0.0.1:18789 会"拒绝连接",是 issue #46/#48 的根因。 -REM 方案:立刻打开本地"启动首屏"loading.html,给用户即时反馈(移植自 4.0 splash)。 -REM 首屏自己轮询 /ready,gateway 真就绪后自动跳 Dashboard——天然解决拒连。 +REM Do not open Dashboard before the gateway is ready. +REM Slow USB drives may need tens of seconds to stage bundled deps. +REM Open the local startup page now, and always open Config Center too. +REM Config Center lets users change models, recharge/get keys, and connect channels. -REM 是否已配置模型?openclaw.json 含 providers 即视为已配置 (issue #24)。 -REM 未配置(首次):先开 Config Center 引导填 Key。 -set "MODEL_CONFIGURED=" -findstr /C:"providers" "%STATE_DIR%\openclaw.json" >nul 2>&1 -if %errorlevel%==0 set "MODEL_CONFIGURED=1" - -REM 立刻开启动首屏(带 port 参数,就绪后自动跳 Dashboard) -REM 用 file:/// URL(正斜杠)+ 转义 & ,确保 query string 能传给浏览器。 +REM Open startup page with the gateway port and token in the query string. echo Opening startup screen... set "LOADING_PATH=%UCLAW_DIR%lib\loading.html" set "LOADING_URL=file:///%LOADING_PATH:\=/%?port=%PORT%&token=uclaw" start "" "%LOADING_URL%" -if not defined MODEL_CONFIGURED ( - echo First-time setup - opening Config Center... - start "" http://127.0.0.1:18788/ -) +echo Opening Config Center... +start "" http://127.0.0.1:18788/ -REM 后台等待器兜底:万一首屏页没起作用(浏览器拦本地 fetch 等), -REM 仍轮询端口,gateway LISTENING 后开 Dashboard。 +REM Fallback watcher: if the startup page cannot poll from file URLs, +REM keep polling and reopen Config Center after the gateway is ready. start /B "" cmd /c ""%UCLAW_DIR%lib\wait-gateway.bat" %PORT%" -REM gateway 首轮预热(后台、静默、非阻塞):就绪后先唤醒 config/model 子系统, -REM 用户首次点发送时不再等。移植自 4.0 first-turn-prewarm。 +REM Prewarm gateway in the background after it becomes ready. start /B "" "%NODE_BIN%" "%UCLAW_DIR%lib\prewarm.mjs" %PORT% uclaw >nul 2>&1 echo. @@ -194,7 +183,7 @@ echo ======================================== echo Starting OpenClaw Gateway on port %PORT%... echo First run on a USB drive may take 30-90 seconds echo (unpacking bundled components). Please wait; -echo the Dashboard opens automatically when ready. +echo Config Center is open for model, key, recharge, and channel setup. echo DO NOT close this window while using U-Claw! echo ======================================== echo. diff --git a/portable/config-server/public/index.html b/portable/config-server/public/index.html index 5022a39..e3b1b0b 100644 --- a/portable/config-server/public/index.html +++ b/portable/config-server/public/index.html @@ -178,9 +178,15 @@ input:focus { border-color: #ff6b35; }

选择 AI 模型

-

推荐国内用户用 MiniMax / Kimi / DeepSeek

+

最省心:用「虾盘云」一个 Key 调用国内外全部大模型(中转站)。也可用下面各家自己的官方 Key。

+
+ +

虾盘云 首选中转站

+

一个 Key 用 DeepSeek / Claude / GPT / 通义 等国内外全部大模型,无需翻墙

+ → 注册 / 充值 / 获取 API Key +

MiniMax 推荐国内

@@ -259,7 +265,7 @@ input:focus { border-color: #ff6b35; }

请填写对应模型的 API Key

-

📌 如何获取 API Key?

+

📌 获取 / 充值 API Key

@@ -456,7 +462,7 @@ function goStep(n) { } const PROVIDER_NAMES = { - minimax: 'MiniMax', kimi: 'Kimi (月之暗面)', deepseek: 'DeepSeek', + 'uclaw-cloud': '虾盘云', minimax: 'MiniMax', kimi: 'Kimi (月之暗面)', deepseek: 'DeepSeek', zai: '智谱 GLM', qwen: '通义千问', doubao: '豆包', openai: 'OpenAI', anthropic: 'Anthropic Claude', groq: 'Groq', siliconflow: '硅基流动', custom: '自定义' @@ -474,7 +480,8 @@ function setupStep2() { var linksDiv = document.getElementById('providerLinks'); linksDiv.innerHTML = ''; if (buyLink) { - linksDiv.innerHTML = '🔑 ' + name + ' — 获取 API Key'; + var action = buyLink.dataset.actionLabel || '获取 API Key'; + linksDiv.innerHTML = '🔑 ' + name + ' — ' + action + ''; } linksDiv.innerHTML += '🔑 MiniMax — 国内推荐,注册送额度' + '🔑 智谱 GLM — 有免费额度' + @@ -492,7 +499,7 @@ function togglePw(id) { // --- Build OpenClaw config --- function buildConfig(provider, base, model, apiKey) { var baseConfig = { - gateway: { auth: { mode: 'token', token: 'uclaw' } }, + gateway: { auth: { mode: 'token', token: 'uclaw' }, remote: { token: 'uclaw' } }, commands: { native: 'auto', nativeSkills: 'auto', restart: true, ownerDisplay: 'raw' }, meta: { lastTouchedVersion: '2026.3.13', lastTouchedAt: new Date().toISOString() } }; diff --git a/portable/lib/loading.html b/portable/lib/loading.html index cef42db..2af204b 100644 --- a/portable/lib/loading.html +++ b/portable/lib/loading.html @@ -7,7 +7,12 @@ +
+ +

U-Claw 正在启动

+
首次从 U 盘启动需要展开内置组件,
稍等片刻,就绪后会提示你下一步。
+
+
+
正在等待 OpenClaw 网关…
+
+
+ 慢 U 盘首次启动通常 30–90 秒。
+ 如果迟迟没反应,可先打开 + 配置中心。 +
+ + +
+ +

U-Claw 已就绪

+
选择下一步 — 直接开始聊天,或先去配置模型和渠道。
+ +
没配过模型或余额不足?先点「配置 / 改模型」处理 Key 或充值。
+
+