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

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'),
});