Files
zclaw_openfang/start-all.ps1
iven 74dbf42644 refactor(startup): simplify stack to Tauri-managed OpenFang + optional ChromeDriver
- Remove OpenFang CLI dependency from startup scripts
- OpenFang now bundled with Tauri and managed via gateway_start/gateway_status commands
- Add bootstrap screen in App.tsx to auto-start local gateway before UI loads
- Update Makefile: replace start-no-gateway with start-desktop-only
- Fix gateway config endpoints: use /api/config instead of /api/config/quick
- Add Playwright dependencies for future E2E testing
2026-03-17 14:08:03 +08:00

202 lines
6.1 KiB
PowerShell

# ZCLAW Full Stack Start Script
# Starts: ChromeDriver (optional) -> Tauri Desktop (manages OpenFang internally)
#
# NOTE: OpenFang is bundled with Tauri and managed internally.
# The frontend uses Tauri commands (gateway_start/gateway_status) to control OpenFang.
# No external OpenFang CLI installation is required.
param(
[switch]$NoBrowser,
[switch]$Dev,
[switch]$Help,
[switch]$Stop,
[switch]$DesktopOnly
)
$ErrorActionPreference = "Continue"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Colors
function info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Cyan }
function ok { param($msg) Write-Host "[OK] $msg" -ForegroundColor Green }
function warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function err { param($msg) Write-Host "[ERROR] $msg" -ForegroundColor Red }
if ($Help) {
Write-Host @"
ZCLAW Full Stack Start Script
==============================
Usage: .\start-all.ps1 [options]
Options:
-DesktopOnly Start desktop only (skip ChromeDriver)
-NoBrowser Skip ChromeDriver startup
-Dev Development mode (hot reload)
-Stop Stop all services
-Help Show this help
Note:
OpenFang is bundled with the Tauri app and managed internally.
The app will start OpenFang automatically via Tauri commands.
No external OpenFang CLI installation required.
Quick Commands:
pnpm start # Start all services
pnpm start:dev # Start in dev mode
pnpm start:desktop # Start desktop only (no browser)
"@
exit 0
}
# Stop all services
if ($Stop) {
info "Stopping all ZCLAW services..."
# Stop ChromeDriver
Get-Process -Name "chromedriver" -ErrorAction SilentlyContinue | Stop-Process -Force
ok "ChromeDriver stopped"
# Stop any process on port 4200 (OpenFang)
$port4200 = netstat -ano | Select-String ":4200.*LISTENING"
if ($port4200) {
$pid4200 = ($port4200 -split '\s+')[-1]
if ($pid4200 -match '^\d+$') {
Stop-Process -Id $pid4200 -Force -ErrorAction SilentlyContinue
ok "Stopped process on port 4200 (PID: $pid4200)"
}
}
# Stop Tauri/ZClaw
Get-Process -Name "ZClaw" -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process -Name "desktop" -ErrorAction SilentlyContinue | Stop-Process -Force
ok "ZCLAW Desktop stopped"
# Kill any process on port 1420 (Vite dev server)
$port1420 = netstat -ano | Select-String ":1420.*LISTENING"
if ($port1420) {
$pid1420 = ($port1420 -split '\s+')[-1]
if ($pid1420 -match '^\d+$') {
Stop-Process -Id $pid1420 -Force -ErrorAction SilentlyContinue
ok "Killed process on port 1420 (PID: $pid1420)"
}
}
ok "All services stopped"
exit 0
}
Write-Host ""
Write-Host "===============================================" -ForegroundColor Magenta
Write-Host " ZCLAW - OpenFang Desktop Client" -ForegroundColor Magenta
Write-Host "===============================================" -ForegroundColor Magenta
Write-Host ""
# Track processes for cleanup
$Jobs = @()
function Cleanup {
info "Cleaning up..."
foreach ($job in $Jobs) {
if ($job -and !$job.HasExited) {
info "Stopping $($job.ProcessName) (PID: $($job.Id))"
try { $job.Kill() } catch {}
}
}
}
trap { Cleanup; break }
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Cleanup } | Out-Null
# Skip ChromeDriver if DesktopOnly
if ($DesktopOnly) {
$NoBrowser = $true
}
# 1. ChromeDriver (optional - for Browser Hand automation)
if (-not $NoBrowser) {
info "Checking ChromeDriver..."
$existing = Get-Process -Name "chromedriver" -ErrorAction SilentlyContinue
if ($existing) {
ok "ChromeDriver already running (PID: $($existing.Id))"
} else {
$chromedriver = Get-Command chromedriver -ErrorAction SilentlyContinue
if ($chromedriver) {
ok "ChromeDriver found: $($chromedriver.Source)"
info "Starting ChromeDriver on port 4444..."
$proc = Start-Process -FilePath "chromedriver" -ArgumentList "--port=4444" -PassThru -WindowStyle Hidden
$Jobs += $proc
Start-Sleep -Milliseconds 500
if ($proc.HasExited) {
warn "ChromeDriver exited. Check if port 4444 is in use."
} else {
ok "ChromeDriver started (PID: $($proc.Id))"
}
} else {
warn "ChromeDriver not found. Browser automation disabled."
info "Download: https://chromedriver.chromium.org/downloads"
}
}
} else {
info "Skipping ChromeDriver"
}
Write-Host ""
# 2. Check OpenFang Runtime
info "Checking OpenFang runtime..."
$runtimePath = "$ScriptDir/desktop/src-tauri/resources/openfang-runtime"
if (Test-Path "$runtimePath/openfang.exe") {
ok "OpenFang runtime found (bundled)"
} elseif (Test-Path "$runtimePath/openfang") {
ok "OpenFang runtime found (bundled)"
} else {
warn "OpenFang runtime not found at $runtimePath"
info "Run: cd desktop && pnpm prepare:openfang-runtime"
}
Write-Host ""
# 3. Start Tauri Desktop
info "Starting ZCLAW Desktop..."
Set-Location "$ScriptDir/desktop"
# Check if port 1420 is in use
$port1420 = netstat -ano | Select-String ":1420.*LISTENING"
if ($port1420) {
$pid1420 = ($port1420 -split '\s+')[-1]
if ($pid1420 -match '^\d+$') {
warn "Port 1420 is in use by PID $pid1420. Killing..."
Stop-Process -Id $pid1420 -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
}
}
if ($Dev) {
info "Development mode enabled"
info "OpenFang will be started by the app via Tauri commands"
pnpm tauri dev
} else {
$exe = "src-tauri\target\release\ZClaw.exe"
if (Test-Path $exe) {
info "Starting built application..."
Start-Process $exe
ok "ZCLAW Desktop started"
} else {
info "Built app not found, using dev mode..."
pnpm tauri dev
}
}
if ($Dev) {
Write-Host ""
info "Press Ctrl+C to stop all services..."
try { while ($true) { Start-Sleep -Seconds 1 } }
finally { Cleanup }
}