feat: restructure repo for collaboration + add desktop app source

- Reorganize project: clean structure (portable/ u-claw-app/ usb-scripts/ website/)
- Move docs into website/, rename uclaw-scripts to usb-scripts
- Add u-claw-app/ Electron desktop source code
- Add portable/setup.sh: one-command dev environment setup
- Add portable/SkillHub.html: skill marketplace page
- Update README: dev guide, contribution workflow, project structure
- Update .gitignore: exclude runtime binaries and build artifacts
- Expand China install guide: npm mirrors, detailed onboard wizard
This commit is contained in:
dongsheng123132
2026-03-12 10:59:26 +08:00
parent 75b5daab57
commit be734cb111
21 changed files with 16931 additions and 171 deletions

BIN
u-claw-app/assets/icon.icns Normal file

Binary file not shown.

BIN
u-claw-app/assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

BIN
u-claw-app/assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

View File

@@ -0,0 +1,54 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<defs>
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#1a1a2e"/>
<stop offset="100%" style="stop-color:#0a0a1a"/>
</linearGradient>
<linearGradient id="claw" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#ff8f65"/>
<stop offset="100%" style="stop-color:#ff6b35"/>
</linearGradient>
<filter id="glow">
<feGaussianBlur stdDeviation="8" result="blur"/>
<feMerge><feMergeNode in="blur"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
</defs>
<!-- Background -->
<rect width="1024" height="1024" rx="200" fill="url(#bg)"/>
<!-- Outer ring -->
<circle cx="512" cy="512" r="420" fill="none" stroke="#ff6b35" stroke-width="6" opacity="0.15"/>
<circle cx="512" cy="512" r="380" fill="none" stroke="#ff6b35" stroke-width="3" opacity="0.1"/>
<!-- Lobster/Claw body -->
<g filter="url(#glow)">
<!-- Main claw shape -->
<path d="M280 440 C280 280, 400 180, 512 300 C624 180, 744 280, 744 440 C744 600, 660 720, 512 760 C364 720, 280 600, 280 440Z"
fill="url(#claw)" opacity="0.95"/>
<!-- Left pincer -->
<path d="M320 380 C280 300, 220 320, 240 380 C260 440, 310 420, 340 400Z"
fill="#ff8f65" opacity="0.8"/>
<!-- Right pincer -->
<path d="M704 380 C744 300, 804 320, 784 380 C764 440, 714 420, 684 400Z"
fill="#ff8f65" opacity="0.8"/>
</g>
<!-- U letter -->
<path d="M380 400 L380 560 C380 640, 440 700, 512 700 C584 700, 644 640, 644 560 L644 400"
fill="none" stroke="#ffffff" stroke-width="40" stroke-linecap="round" stroke-linejoin="round"/>
<!-- Eyes -->
<circle cx="430" cy="360" r="24" fill="#ffffff"/>
<circle cx="594" cy="360" r="24" fill="#ffffff"/>
<circle cx="435" cy="355" r="10" fill="#1a1a2e"/>
<circle cx="599" cy="355" r="10" fill="#1a1a2e"/>
<!-- Antennae -->
<path d="M430 320 C420 260, 360 220, 320 200" fill="none" stroke="#ff8f65" stroke-width="8" stroke-linecap="round" opacity="0.7"/>
<path d="M594 320 C604 260, 664 220, 704 200" fill="none" stroke="#ff8f65" stroke-width="8" stroke-linecap="round" opacity="0.7"/>
<circle cx="316" cy="196" r="12" fill="#ff6b35" opacity="0.8"/>
<circle cx="708" cy="196" r="12" fill="#ff6b35" opacity="0.8"/>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

13651
u-claw-app/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

109
u-claw-app/package.json Normal file
View File

@@ -0,0 +1,109 @@
{
"name": "u-claw",
"version": "2.0.0",
"description": "U-Claw - AI Assistant Desktop App",
"main": "src/main.js",
"author": "dongsheng <hefangsheng@gmail.com>",
"license": "MIT",
"homepage": "https://u-claw.org",
"scripts": {
"start": "electron .",
"dev": "electron . --dev",
"build:mac": "electron-builder --mac",
"build:mac-arm64": "electron-builder --mac --arm64",
"build:mac-x64": "electron-builder --mac --x64",
"build:win": "electron-builder --win",
"build:all": "electron-builder --mac --win",
"postinstall": "electron-builder install-app-deps"
},
"build": {
"appId": "org.u-claw.desktop",
"productName": "U-Claw",
"copyright": "Copyright © 2026 U-Claw",
"directories": {
"output": "release"
},
"files": [
"src/**/*",
"assets/**/*",
"node_modules/**/*",
"!node_modules/**/*.md",
"!node_modules/**/CHANGELOG*",
"!node_modules/**/test/**",
"!node_modules/**/tests/**",
"!node_modules/**/.cache"
],
"asar": false,
"extraResources": [
{
"from": "resources/Config.html",
"to": "resources/Config.html"
},
{
"from": "resources/context",
"to": "resources/context"
},
{
"from": "resources/runtime/node-${platform}-${arch}",
"to": "resources/runtime/node-${platform}-${arch}"
}
],
"mac": {
"category": "public.app-category.developer-tools",
"icon": "assets/icon.icns",
"identity": null,
"target": [
{
"target": "dmg",
"arch": ["arm64", "x64"]
}
],
"hardenedRuntime": false,
"gatekeeperAssess": false
},
"dmg": {
"title": "U-Claw",
"icon": "assets/icon.icns",
"contents": [
{ "x": 130, "y": 220 },
{ "x": 410, "y": 220, "type": "link", "path": "/Applications" }
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": ["x64"]
},
{
"target": "portable",
"arch": ["x64"]
}
],
"icon": "assets/icon.ico"
},
"nsis": {
"oneClick": true,
"perMachine": false,
"allowToChangeInstallationDirectory": false,
"installerIcon": "assets/icon.ico",
"uninstallerIcon": "assets/icon.ico",
"installerHeaderIcon": "assets/icon.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "U-Claw"
},
"linux": {
"target": ["AppImage"],
"icon": "assets/icon.png",
"category": "Development"
}
},
"dependencies": {
"openclaw": "latest"
},
"devDependencies": {
"electron": "^35.0.0",
"electron-builder": "^26.0.0"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
# U-Claw Agent Context
You are U-Claw, a desktop AI assistant built on OpenClaw.
U-Claw is designed for Chinese users with seamless access to domestic AI models.
## Supported Models (No VPN Required)
- DeepSeek: Best for coding, most cost-effective
- Kimi (Moonshot): 256K context, great for long documents
- Qwen (Tongyi Qianwen): Large free quota from Alibaba
- GLM (Zhipu AI): Academic and Chinese NLP
- MiniMax: Voice and multimodal
- Doubao (ByteDance): Volcano Engine platform
- SiliconFlow: API relay, multiple models
## International Models
- Claude (Anthropic)
- GPT (OpenAI)
- Ollama (Local models)
## Key Features
- Chinese-first configuration (Config.html)
- Pre-configured China npm mirror
- QQ Bot integration ready
- Portable USB deployment supported
## Contact
- Website: u-claw.org
- WeChat: hecare888
- GitHub: dongsheng123132

View File

@@ -0,0 +1,85 @@
#!/usr/bin/env node
// Generate PNG icon from SVG, then create ICNS and ICO
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const assetsDir = path.join(__dirname, '..', 'assets');
const svgPath = path.join(assetsDir, 'icon.svg');
const pngPath = path.join(assetsDir, 'icon.png');
// Check if sips is available (macOS)
try {
// Use rsvg-convert or sips to create PNG from SVG
// First try rsvg-convert
try {
execSync(`rsvg-convert -w 1024 -h 1024 "${svgPath}" -o "${pngPath}"`, { stdio: 'inherit' });
console.log('Created icon.png via rsvg-convert');
} catch {
// Fallback: create a simple PNG placeholder using sips
// sips can't convert SVG directly, so we'll use a different approach
console.log('rsvg-convert not found, trying alternative...');
// Try using Python with cairosvg
try {
execSync(`python3 -c "
import cairosvg
cairosvg.svg2png(url='${svgPath}', write_to='${pngPath}', output_width=1024, output_height=1024)
"`, { stdio: 'inherit' });
console.log('Created icon.png via cairosvg');
} catch {
console.log('cairosvg not available either.');
console.log('Please install: brew install librsvg OR pip3 install cairosvg');
console.log('Then run this script again.');
console.log('');
console.log('Or manually convert assets/icon.svg to assets/icon.png (1024x1024)');
process.exit(1);
}
}
// Create ICNS for macOS
const iconsetDir = path.join(assetsDir, 'icon.iconset');
fs.mkdirSync(iconsetDir, { recursive: true });
const sizes = [16, 32, 64, 128, 256, 512, 1024];
for (const size of sizes) {
const outFile = size === 1024
? path.join(iconsetDir, 'icon_512x512@2x.png')
: path.join(iconsetDir, `icon_${size}x${size}.png`);
execSync(`sips -z ${size} ${size} "${pngPath}" --out "${outFile}"`, { stdio: 'pipe' });
// Also create @2x versions
if (size <= 512 && size > 16) {
const halfSize = size / 2;
const out2x = path.join(iconsetDir, `icon_${halfSize}x${halfSize}@2x.png`);
execSync(`sips -z ${size} ${size} "${pngPath}" --out "${out2x}"`, { stdio: 'pipe' });
}
}
execSync(`iconutil -c icns "${iconsetDir}" -o "${path.join(assetsDir, 'icon.icns')}"`, { stdio: 'inherit' });
console.log('Created icon.icns');
// Clean up iconset
fs.rmSync(iconsetDir, { recursive: true });
// Create ICO for Windows (use png2ico or ImageMagick)
try {
// Try with ImageMagick
execSync(`convert "${pngPath}" -define icon:auto-resize=256,128,64,48,32,16 "${path.join(assetsDir, 'icon.ico')}"`, { stdio: 'inherit' });
console.log('Created icon.ico via ImageMagick');
} catch {
try {
// Try with sips + manual
execSync(`sips -z 256 256 "${pngPath}" --out "${path.join(assetsDir, 'icon-256.png')}"`, { stdio: 'pipe' });
console.log('Created icon-256.png (manual ICO conversion needed)');
console.log('Install ImageMagick for ICO: brew install imagemagick');
} catch {
console.log('Could not create ICO. Install ImageMagick: brew install imagemagick');
}
}
console.log('Icon generation complete!');
} catch (err) {
console.error('Error generating icons:', err.message);
process.exit(1);
}

138
u-claw-app/src/loading.html Normal file
View File

@@ -0,0 +1,138 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>U-Claw - Loading</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, "Microsoft YaHei", "Segoe UI", sans-serif;
background: #0a0a0a;
color: #e0e0e0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
-webkit-app-region: drag;
}
.container {
text-align: center;
-webkit-app-region: no-drag;
}
.logo {
width: 120px;
height: 120px;
margin: 0 auto 24px;
animation: pulse 2s ease-in-out infinite;
}
.logo svg {
width: 100%;
height: 100%;
}
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.05); opacity: 0.8; }
}
h1 {
font-size: 2em;
margin-bottom: 8px;
font-weight: 600;
}
h1 span { color: #ff6b35; }
.subtitle {
color: #888;
font-size: 1.1em;
margin-bottom: 32px;
}
.loader {
width: 200px;
height: 3px;
background: #222;
border-radius: 3px;
margin: 0 auto 16px;
overflow: hidden;
}
.loader-bar {
height: 100%;
width: 40%;
background: linear-gradient(90deg, #ff6b35, #ff8f65);
border-radius: 3px;
animation: loading 1.5s ease-in-out infinite;
}
@keyframes loading {
0% { transform: translateX(-100%); }
100% { transform: translateX(350%); }
}
.status {
color: #666;
font-size: 0.9em;
}
.status span {
animation: dots 1.5s steps(4) infinite;
}
@keyframes dots {
0% { content: ''; }
25% { content: '.'; }
50% { content: '..'; }
75% { content: '...'; }
}
</style>
</head>
<body>
<div class="container">
<div class="logo">
<svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
<!-- Lobster/Claw icon -->
<circle cx="60" cy="60" r="55" fill="none" stroke="#ff6b35" stroke-width="2" opacity="0.3"/>
<circle cx="60" cy="60" r="40" fill="none" stroke="#ff6b35" stroke-width="1.5" opacity="0.2"/>
<!-- Claw shape -->
<path d="M35 55 C35 35, 55 25, 60 40 C65 25, 85 35, 85 55 C85 70, 75 80, 60 85 C45 80, 35 70, 35 55Z"
fill="#ff6b35" opacity="0.9"/>
<!-- U shape inside -->
<path d="M45 50 L45 65 C45 75, 55 80, 60 80 C65 80, 75 75, 75 65 L75 50"
fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round"/>
<!-- Eyes -->
<circle cx="50" cy="45" r="3" fill="#fff"/>
<circle cx="70" cy="45" r="3" fill="#fff"/>
</svg>
</div>
<h1><span>U-Claw</span></h1>
<p class="subtitle">AI Assistant / AI 助手</p>
<div class="loader"><div class="loader-bar"></div></div>
<p class="status" id="status">Starting OpenClaw engine...</p>
</div>
<script>
const messages = [
'Starting OpenClaw engine...',
'正在启动 OpenClaw 引擎...',
'Checking configuration...',
'检查配置文件...',
'Initializing AI gateway...',
'初始化 AI 网关...',
];
let i = 0;
setInterval(() => {
document.getElementById('status').textContent = messages[i % messages.length];
i++;
}, 2000);
// Check if gateway is ready via IPC
async function checkReady() {
try {
if (window.uclaw) {
const status = await window.uclaw.getGatewayStatus();
if (status.ready) {
document.getElementById('status').textContent = 'Ready! / 就绪!';
// Main process will handle navigation
return;
}
}
} catch(e) {}
setTimeout(checkReady, 1000);
}
checkReady();
</script>
</body>
</html>

419
u-claw-app/src/main.js Normal file
View File

@@ -0,0 +1,419 @@
const { app, BrowserWindow, Menu, Tray, shell, dialog, ipcMain } = require('electron');
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const http = require('http');
// ── Constants ──
const APP_NAME = 'U-Claw';
const DEFAULT_PORT = 18789;
const MAX_PORT = 18799;
const GATEWAY_STARTUP_TIMEOUT = 30000;
// ── Paths ──
const isDev = process.argv.includes('--dev');
const appRoot = isDev ? __dirname + '/..' : process.resourcesPath + '/..';
const resourcesPath = isDev
? path.join(__dirname, '..', 'resources')
: path.join(process.resourcesPath, 'resources');
// OpenClaw core location
const openclawPath = isDev
? path.join(__dirname, '..', 'node_modules', 'openclaw')
: path.join(process.resourcesPath, 'app', 'node_modules', 'openclaw');
const openclawEntry = path.join(openclawPath, 'openclaw.mjs');
// Bundled Node.js runtime (OpenClaw needs standalone Node, not Electron's)
function getNodeBin() {
const platform = process.platform;
const arch = process.arch;
if (isDev) {
const devNodeDir = path.join(__dirname, '..', 'resources', 'runtime', `node-${platform}-${arch}`);
const devNodeBin = platform === 'win32'
? path.join(devNodeDir, 'node.exe')
: path.join(devNodeDir, 'bin', 'node');
if (fs.existsSync(devNodeBin)) return devNodeBin;
return 'node';
}
const nodeDir = path.join(process.resourcesPath, 'resources', 'runtime', `node-${platform}-${arch}`);
const nodeBin = platform === 'win32'
? path.join(nodeDir, 'node.exe')
: path.join(nodeDir, 'bin', 'node');
if (fs.existsSync(nodeBin)) return nodeBin;
return 'node';
}
// User data
const userDataPath = app.getPath('userData');
const configDir = path.join(userDataPath, '.openclaw');
const configPath = path.join(configDir, 'openclaw.json');
// ── State ──
let mainWindow = null;
let tray = null;
let gatewayProcess = null;
let gatewayPort = DEFAULT_PORT;
let gatewayReady = false;
let configServerPort = null; // mini HTTP server for Config.html
// ── Config Management ──
function ensureConfig() {
fs.mkdirSync(configDir, { recursive: true });
fs.mkdirSync(path.join(userDataPath, 'memory'), { recursive: true });
fs.mkdirSync(path.join(userDataPath, 'backups'), { recursive: true });
if (!fs.existsSync(configPath)) {
const defaultConfig = {
gateway: {
mode: 'local',
auth: { token: 'uclaw' }
}
};
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
console.log(`[${APP_NAME}] Created default config at ${configPath}`);
}
}
function getConfig() {
try {
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
} catch {
return { gateway: { mode: 'local', auth: { token: 'uclaw' } } };
}
}
function hasModelConfigured() {
const config = getConfig();
return !!(config.agent && config.agent.model);
}
function getToken() {
const config = getConfig();
return config?.gateway?.auth?.token || 'uclaw';
}
// ── Port Detection ──
function isPortAvailable(port) {
return new Promise((resolve) => {
const server = require('net').createServer();
server.once('error', () => resolve(false));
server.once('listening', () => {
server.close();
resolve(true);
});
server.listen(port, '127.0.0.1');
});
}
async function findAvailablePort() {
for (let port = DEFAULT_PORT; port <= MAX_PORT; port++) {
if (await isPortAvailable(port)) return port;
}
throw new Error(`No available port in range ${DEFAULT_PORT}-${MAX_PORT}`);
}
// ── Mini HTTP Server for Config.html ──
// Serves Config.html on localhost so WebSocket origin is http://127.0.0.1:xxx
// (OpenClaw gateway rejects non-http origins like file:// or custom protocols)
function startConfigServer() {
return new Promise((resolve) => {
const server = http.createServer((req, res) => {
const configHtml = path.join(resourcesPath, 'Config.html');
if (fs.existsSync(configHtml)) {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
fs.createReadStream(configHtml).pipe(res);
} else {
res.writeHead(404);
res.end('Config.html not found');
}
});
// Listen on random available port
server.listen(0, '127.0.0.1', () => {
configServerPort = server.address().port;
console.log(`[${APP_NAME}] Config server on http://127.0.0.1:${configServerPort}`);
resolve(configServerPort);
});
});
}
function getConfigURL() {
return `http://127.0.0.1:${configServerPort}/?port=${gatewayPort}`;
}
// ── Gateway Management ──
function startGateway(port) {
return new Promise((resolve, reject) => {
console.log(`[${APP_NAME}] Starting OpenClaw gateway on port ${port}...`);
const nodeBin = getNodeBin();
console.log(`[${APP_NAME}] Using Node.js: ${nodeBin}`);
const env = {
...process.env,
OPENCLAW_HOME: userDataPath,
OPENCLAW_STATE_DIR: configDir,
OPENCLAW_CONFIG_PATH: configPath,
OPENCLAW_EMBEDDED_IN: APP_NAME,
};
gatewayProcess = spawn(nodeBin, [
openclawEntry,
'gateway', 'run',
'--allow-unconfigured',
'--force',
'--port', String(port),
], {
env,
cwd: openclawPath,
stdio: ['pipe', 'pipe', 'pipe'],
});
gatewayProcess.stdout.on('data', (data) => {
const msg = data.toString().trim();
if (msg) console.log(`[OpenClaw] ${msg}`);
});
gatewayProcess.stderr.on('data', (data) => {
const msg = data.toString().trim();
if (msg) console.error(`[OpenClaw:err] ${msg}`);
});
gatewayProcess.on('error', (err) => {
console.error(`[${APP_NAME}] Gateway process error:`, err);
reject(err);
});
gatewayProcess.on('exit', (code) => {
console.log(`[${APP_NAME}] Gateway exited with code ${code}`);
gatewayProcess = null;
gatewayReady = false;
});
// Poll for gateway readiness
const startTime = Date.now();
const checkReady = () => {
if (Date.now() - startTime > GATEWAY_STARTUP_TIMEOUT) {
reject(new Error('Gateway startup timeout'));
return;
}
const req = http.get(`http://127.0.0.1:${port}/`, (res) => {
gatewayReady = true;
gatewayPort = port;
console.log(`[${APP_NAME}] Gateway ready on port ${port}`);
resolve(port);
});
req.on('error', () => setTimeout(checkReady, 500));
req.setTimeout(2000, () => {
req.destroy();
setTimeout(checkReady, 500);
});
};
setTimeout(checkReady, 1000);
});
}
function stopGateway() {
if (gatewayProcess) {
console.log(`[${APP_NAME}] Stopping gateway...`);
gatewayProcess.kill('SIGTERM');
setTimeout(() => {
if (gatewayProcess) gatewayProcess.kill('SIGKILL');
}, 5000);
}
}
// ── Window Management ──
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
title: APP_NAME,
icon: path.join(__dirname, '..', 'assets', 'icon.png'),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
},
show: false,
backgroundColor: '#0a0a0a',
});
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
// Open external links in browser
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('http')) shell.openExternal(url);
return { action: 'deny' };
});
loadAppPage();
}
function loadAppPage() {
if (!mainWindow) return;
if (gatewayReady) {
const token = getToken();
mainWindow.loadURL(`http://127.0.0.1:${gatewayPort}/#token=${token}`);
} else {
const loadingHtml = path.join(__dirname, 'loading.html');
mainWindow.loadFile(loadingHtml);
}
}
function loadConfigPage() {
if (!mainWindow || !gatewayReady || !configServerPort) return;
mainWindow.loadURL(getConfigURL());
}
// ── Menu ──
function createMenu() {
const template = [
{
label: APP_NAME,
submenu: [
{ label: `About ${APP_NAME}`, role: 'about' },
{ type: 'separator' },
{
label: '配置助手 / Configuration',
accelerator: 'CmdOrCtrl+,',
click: () => loadConfigPage()
},
{
label: 'Dashboard',
accelerator: 'CmdOrCtrl+D',
click: () => {
if (mainWindow && gatewayReady) {
const token = getToken();
mainWindow.loadURL(`http://127.0.0.1:${gatewayPort}/#token=${token}`);
}
}
},
{ type: 'separator' },
{
label: 'Open Data Folder',
click: () => shell.openPath(userDataPath)
},
{ type: 'separator' },
{ label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: () => app.quit() }
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Help',
submenu: [
{
label: 'Website',
click: () => shell.openExternal('https://u-claw.org')
},
{
label: 'WeChat: hecare888',
click: () => {
dialog.showMessageBox({ message: 'WeChat / 微信: hecare888', type: 'info' });
}
}
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
// ── IPC Handlers ──
function setupIPC() {
ipcMain.handle('get-gateway-status', () => ({
ready: gatewayReady,
port: gatewayPort,
token: getToken(),
hasModel: hasModelConfigured(),
}));
ipcMain.handle('open-dashboard', () => {
if (mainWindow && gatewayReady) {
const token = getToken();
mainWindow.loadURL(`http://127.0.0.1:${gatewayPort}/#token=${token}`);
}
});
ipcMain.handle('open-config', () => loadConfigPage());
}
// ── App Lifecycle ──
app.whenReady().then(async () => {
console.log(`[${APP_NAME}] v${app.getVersion()} starting...`);
// Setup
ensureConfig();
createMenu();
setupIPC();
createWindow();
// Start mini HTTP server for Config.html
await startConfigServer();
try {
// Find port and start gateway
const port = await findAvailablePort();
await startGateway(port);
// Gateway is ready, load the appropriate page
loadAppPage();
} catch (err) {
console.error(`[${APP_NAME}] Failed to start gateway:`, err);
dialog.showErrorBox(
`${APP_NAME} - Startup Error`,
`Failed to start OpenClaw gateway.\n\n${err.message}\n\nPlease check if Node.js is available and try again.`
);
}
});
app.on('window-all-closed', () => {
stopGateway();
app.quit();
});
app.on('before-quit', () => {
stopGateway();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

View File

@@ -0,0 +1,7 @@
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('uclaw', {
getGatewayStatus: () => ipcRenderer.invoke('get-gateway-status'),
openDashboard: () => ipcRenderer.invoke('open-dashboard'),
openConfig: () => ipcRenderer.invoke('open-config'),
});