From c0d047496bf1924071032cd6b4f47d9e4c307f9a Mon Sep 17 00:00:00 2001 From: dongsheng123132 <90887123+dongsheng123132@users.noreply.github.com> Date: Thu, 19 Mar 2026 15:50:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(app):=20=E9=A6=96=E6=AC=A1=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=87=AA=E5=8A=A8=E8=B7=B3=E9=85=8D=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=20+=20config-server=20=E6=94=AF=E6=8C=81=20API=20=E8=AF=BB?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启动时检测 hasModelConfigured(),未配置则跳 Config.html - config-server 新增 GET/POST /api/config 和 POST /api/done - Config.html 保存配置后自动跳转 Dashboard --- u-claw-app/src/main.js | 54 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/u-claw-app/src/main.js b/u-claw-app/src/main.js index 4ea7998..ebd6f46 100644 --- a/u-claw-app/src/main.js +++ b/u-claw-app/src/main.js @@ -139,6 +139,51 @@ async function findAvailablePort() { function startConfigServer() { return new Promise((resolve) => { const server = http.createServer((req, res) => { + const url = new URL(req.url, `http://${req.headers.host}`); + + // GET /api/config — return current config + if (req.method === 'GET' && url.pathname === '/api/config') { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify(getConfig())); + return; + } + + // POST /api/config — save/merge config + if (req.method === 'POST' && url.pathname === '/api/config') { + let body = ''; + req.on('data', chunk => body += chunk); + req.on('end', () => { + try { + const newConfig = JSON.parse(body); + const existing = getConfig(); + const merged = Object.assign(existing, newConfig); + fs.writeFileSync(configPath, JSON.stringify(merged, null, 2)); + console.log(`[${APP_NAME}] Config saved`); + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ ok: true })); + } catch (e) { + res.writeHead(400, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ error: e.message })); + } + }); + return; + } + + // POST /api/done — config complete, load dashboard + if (req.method === 'POST' && url.pathname === '/api/done') { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ ok: true })); + // Switch to dashboard after short delay + setTimeout(() => { + if (mainWindow && gatewayReady) { + const token = getToken(); + mainWindow.loadURL(`http://127.0.0.1:${gatewayPort}/#token=${token}`); + } + }, 500); + return; + } + + // Default: serve Config.html const configHtml = path.join(resourcesPath, 'Config.html'); if (fs.existsSync(configHtml)) { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); @@ -412,8 +457,13 @@ app.whenReady().then(async () => { const port = await findAvailablePort(); await startGateway(port); - // Gateway is ready, load the appropriate page - loadAppPage(); + // Gateway is ready — if no model configured, show Config.html first + if (hasModelConfigured()) { + loadAppPage(); + } else { + console.log(`[${APP_NAME}] No model configured, opening Config.html`); + loadConfigPage(); + } } catch (err) { console.error(`[${APP_NAME}] Failed to start gateway:`, err); dialog.showErrorBox(