Monorepo for Aesthetic.Computer aesthetic.computer
at main 153 lines 9.0 kB view raw
1<# 2.SYNOPSIS 3 Aesthetic Computer Platform Launcher for Windows 4 5.DESCRIPTION 6 Starts the Aesthetic Computer devcontainer with VS Code CDP debugging enabled. 7 Sets up HOST_IP for WebRTC, launches devcontainer, and starts clipboard listener. 8 9.NOTES 10 To run this script by just typing `aesthetic` in PowerShell: 11 12 1. Open your PowerShell profile: 13 notepad $PROFILE 14 15 2. Add the following function: 16 17 function aesthetic { 18 powershell.exe -ExecutionPolicy Bypass -File "\\wsl.localhost\Ubuntu\home\me\aesthetic-computer\windows\aesthetic.ps1" 19 } 20 21 3. Save the file, then restart your PowerShell session. 22#> 23 24$ErrorActionPreference = "Stop" 25$workspace = "\\wsl.localhost\Ubuntu\home\me\aesthetic-computer" 26 27# ═══════════════════════════════════════════════════════════════════════════════ 28# Banner 29# ═══════════════════════════════════════════════════════════════════════════════ 30Write-Host @" 31 32 33 34 35 36 37 38 39"@ -ForegroundColor Magenta 40 41# ═══════════════════════════════════════════════════════════════════════════════ 42# Detect HOST_IP (for WebRTC TURN server) 43# ═══════════════════════════════════════════════════════════════════════════════ 44Write-Host "› Detecting HOST_IP..." -ForegroundColor Magenta 45$hostIp = (Get-NetIPAddress -AddressFamily IPv4 ` 46 | Where-Object { $_.InterfaceAlias -match 'Wi-Fi|Ethernet' -and $_.PrefixOrigin -eq 'Dhcp' }).IPAddress | Select-Object -First 1 47 48if ($hostIp) { 49 $env:HOST_IP = $hostIp 50 "HOST_IP=$hostIp" | Out-File -FilePath "$workspace\.devcontainer\envs\host.env" -Encoding ASCII -NoNewline 51 Write-Host "✓ HOST_IP is $hostIp" -ForegroundColor Green 52} else { 53 Write-Host "! Could not detect HOST_IP (WebRTC may not work)" -ForegroundColor Yellow 54} 55 56# ═══════════════════════════════════════════════════════════════════════════════ 57# Kill existing VS Code instances 58# ═══════════════════════════════════════════════════════════════════════════════ 59Write-Host "› Stopping VS Code..." -ForegroundColor Magenta 60Get-Process Code -ErrorAction SilentlyContinue | ForEach-Object { 61 try { 62 $_.CloseMainWindow() | Out-Null 63 Start-Sleep -Milliseconds 500 64 if (!$_.HasExited) { $_.Kill() } 65 } catch {} 66} 67Start-Sleep -Seconds 1 68Write-Host "✓ VS Code stopped" -ForegroundColor Green 69 70# ═══════════════════════════════════════════════════════════════════════════════ 71# Remove old container and start devcontainer 72# ═══════════════════════════════════════════════════════════════════════════════ 73Write-Host "› Starting devcontainer..." -ForegroundColor Magenta 74 75# Remove old container (in WSL) 76wsl -d Ubuntu -e docker rm -f aesthetic 2>$null 77 78# Start devcontainer via CLI (in WSL) 79$devcontainerResult = wsl -d Ubuntu -e bash -c "cd /home/me/aesthetic-computer && devcontainer up --workspace-folder . 2>&1 | tail -3" 80Write-Host $devcontainerResult 81 82if ($LASTEXITCODE -eq 0) { 83 Write-Host "✓ Devcontainer ready" -ForegroundColor Green 84} else { 85 Write-Host "✗ Devcontainer failed to start" -ForegroundColor Red 86 exit 1 87} 88 89# ═══════════════════════════════════════════════════════════════════════════════ 90# Launch VS Code with CDP debugging 91# ═══════════════════════════════════════════════════════════════════════════════ 92Write-Host "› Launching VS Code with CDP on port 9333..." -ForegroundColor Magenta 93 94# Use dev-container+ URI format (hex-encoded workspace path) 95$hexPath = [System.BitConverter]::ToString([System.Text.Encoding]::UTF8.GetBytes("/home/me/aesthetic-computer")).Replace("-","").ToLower() 96$uri = "vscode-remote://dev-container+$hexPath/workspaces/aesthetic-computer" 97 98Start-Process -WindowStyle Hidden -FilePath "code" -ArgumentList ` 99 "--folder-uri", $uri, ` 100 "--remote-debugging-port=9333", ` 101 "--disable-extension", "github.copilot-chat", ` 102 "--disable-extension", "github.copilot" 103 104Write-Host "✓ VS Code launched" -ForegroundColor Green 105 106# ═══════════════════════════════════════════════════════════════════════════════ 107# Install SSL certificate (if needed) 108# ═══════════════════════════════════════════════════════════════════════════════ 109Write-Host "› Checking SSL certificate..." -ForegroundColor Magenta 110 111# Check if mkcert root CA is already trusted 112$certExists = Get-ChildItem -Path Cert:\LocalMachine\Root | Where-Object { $_.Subject -match "mkcert.*@aesthetic" } 113 114if (!$certExists) { 115 Write-Host " ! SSL certificate not installed" -ForegroundColor Yellow 116 Write-Host " › Installing SSL certificate from container..." -ForegroundColor Magenta 117 118 try { 119 # Copy certificate from container 120 $tempCert = "$env:TEMP\mkcert-rootCA.pem" 121 wsl -d Ubuntu -e docker cp aesthetic:/workspaces/aesthetic-computer/ssl-dev/rootCA.pem /tmp/rootCA.pem 2>$null 122 wsl -d Ubuntu -e cat /tmp/rootCA.pem | Out-File -FilePath $tempCert -Encoding ASCII 123 124 if (Test-Path $tempCert) { 125 Import-Certificate -FilePath $tempCert -CertStoreLocation Cert:\LocalMachine\Root | Out-Null 126 Remove-Item $tempCert 127 Write-Host " ✓ SSL certificate installed (restart browser to apply)" -ForegroundColor Green 128 } else { 129 Write-Host " ! Could not copy certificate from container" -ForegroundColor Yellow 130 } 131 } catch { 132 Write-Host " ! Certificate installation failed: $_" -ForegroundColor Yellow 133 } 134} else { 135 Write-Host " ✓ SSL certificate already trusted" -ForegroundColor Green 136} 137 138# ═══════════════════════════════════════════════════════════════════════════════ 139# Clipboard listener (receives from container via netcat) 140# ═══════════════════════════════════════════════════════════════════════════════ 141Write-Host "" 142Write-Host " ✨ aesthetic.computer ready" -ForegroundColor Magenta 143Write-Host "" 144Write-Host "› Starting clipboard listener on port 12345..." -ForegroundColor Gray 145 146while ($true) { 147 try { 148 ncat -l -p 12345 | Set-Clipboard 149 Start-Sleep -Milliseconds 200 150 } catch { 151 Start-Sleep -Seconds 1 152 } 153}