mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
- Add Tauri sidecar architecture: Rust shell spawns claude-server binary, dynamic port allocation, health-check wait loop, graceful shutdown - Fix CORS middleware to accept `tauri://localhost` and `https://tauri.localhost` origins from Tauri WebView, and add CORS headers to /health endpoint - Enable native macOS window decorations (traffic lights) with Overlay title bar, add data-tauri-drag-region on sidebar for window dragging - Conditionally apply desktop-only padding (44px for traffic lights) vs web (12px) - Generate brand identity: light-background app icon, horizontal logo, full icon set (icns/ico/png) for Tauri bundle - Add brand mark + GitHub link in sidebar, replace mascot SVG with app icon in EmptySession page - Update README (zh/en) and docs hero image with new branding - Add sidecar build scripts and launcher entry points - Gitignore Rust target/, Tauri gen/, and brand-assets candidates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
import { mkdir } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
|
|
const desktopRoot = path.resolve(import.meta.dir, '..')
|
|
const repoRoot = path.resolve(desktopRoot, '..')
|
|
const binariesDir = path.join(desktopRoot, 'src-tauri', 'binaries')
|
|
|
|
const targetTriple =
|
|
process.env.TAURI_ENV_TARGET_TRIPLE ||
|
|
process.env.CARGO_BUILD_TARGET ||
|
|
(await detectHostTriple())
|
|
|
|
const bunTarget = mapTargetTripleToBun(targetTriple)
|
|
|
|
await mkdir(binariesDir, { recursive: true })
|
|
|
|
await compileExecutable({
|
|
entrypoint: path.join(desktopRoot, 'sidecars/server-launcher.ts'),
|
|
outfileBase: path.join(binariesDir, `claude-server-${targetTriple}`),
|
|
productName: 'Claude Code Server',
|
|
bunTarget,
|
|
})
|
|
|
|
await compileExecutable({
|
|
entrypoint: path.join(desktopRoot, 'sidecars/cli-launcher.ts'),
|
|
outfileBase: path.join(binariesDir, `claude-cli-${targetTriple}`),
|
|
productName: 'Claude Code CLI',
|
|
bunTarget,
|
|
})
|
|
|
|
console.log(`[build-sidecars] Built desktop sidecars for ${targetTriple} (${bunTarget})`)
|
|
|
|
async function detectHostTriple() {
|
|
const proc = Bun.spawn(['rustc', '-vV'], {
|
|
cwd: repoRoot,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
})
|
|
|
|
const stdout = await new Response(proc.stdout).text()
|
|
const stderr = await new Response(proc.stderr).text()
|
|
const exitCode = await proc.exited
|
|
|
|
if (exitCode !== 0) {
|
|
throw new Error(`[build-sidecars] rustc -vV failed: ${stderr || stdout}`)
|
|
}
|
|
|
|
const hostLine = stdout
|
|
.split('\n')
|
|
.map((line) => line.trim())
|
|
.find((line) => line.startsWith('host: '))
|
|
|
|
if (!hostLine) {
|
|
throw new Error('[build-sidecars] Could not detect Rust host triple')
|
|
}
|
|
|
|
return hostLine.replace('host: ', '')
|
|
}
|
|
|
|
function mapTargetTripleToBun(triple: string) {
|
|
switch (triple) {
|
|
case 'aarch64-apple-darwin':
|
|
return 'bun-darwin-arm64'
|
|
case 'x86_64-apple-darwin':
|
|
return 'bun-darwin-x64'
|
|
case 'x86_64-pc-windows-msvc':
|
|
return 'bun-windows-x64'
|
|
case 'aarch64-pc-windows-msvc':
|
|
return 'bun-windows-arm64'
|
|
case 'x86_64-unknown-linux-gnu':
|
|
return 'bun-linux-x64-baseline'
|
|
case 'aarch64-unknown-linux-gnu':
|
|
return 'bun-linux-arm64'
|
|
case 'x86_64-unknown-linux-musl':
|
|
return 'bun-linux-x64-musl'
|
|
case 'aarch64-unknown-linux-musl':
|
|
return 'bun-linux-arm64-musl'
|
|
default:
|
|
throw new Error(`[build-sidecars] Unsupported target triple: ${triple}`)
|
|
}
|
|
}
|
|
|
|
async function compileExecutable({
|
|
entrypoint,
|
|
outfileBase,
|
|
productName,
|
|
bunTarget,
|
|
}: {
|
|
entrypoint: string
|
|
outfileBase: string
|
|
productName: string
|
|
bunTarget: string
|
|
}) {
|
|
const result = await Bun.build({
|
|
entrypoints: [entrypoint],
|
|
minify: false,
|
|
sourcemap: 'none',
|
|
target: 'bun',
|
|
compile: {
|
|
target: bunTarget,
|
|
outfile: outfileBase,
|
|
autoloadTsconfig: true,
|
|
autoloadPackageJson: true,
|
|
windows: {
|
|
title: productName,
|
|
publisher: 'Claude Code',
|
|
description: productName,
|
|
hideConsole: true,
|
|
},
|
|
},
|
|
})
|
|
|
|
if (!result.success) {
|
|
const logs = result.logs.map((log) => log.message).join('\n')
|
|
throw new Error(`[build-sidecars] Failed to compile ${productName}:\n${logs}`)
|
|
}
|
|
|
|
const outputPath = result.outputs[0]?.path
|
|
console.log(`[build-sidecars] ${productName} -> ${outputPath ?? outfileBase}`)
|
|
}
|