#!/bin/bash # ══════════════════════════════════════════════════ # THE Z AI — Computer Mode Startup (FIXED v4) # ══════════════════════════════════════════════════ echo "===== Application Startup at $(date '+%Y-%m-%d %H:%M:%S') =====" echo "🖥️ Starting Z Computer Mode Server v4..." # ── 1. Start Virtual Display ───────────────────── pkill Xvfb 2>/dev/null || true sleep 0.5 Xvfb :1 -screen 0 1920x1080x24 -ac +extension GLX +render -noreset & XVFB_PID=$! echo "✅ Xvfb started (PID: $XVFB_PID)" sleep 2 # ── 2. Export DISPLAY ──────────────────────────── export DISPLAY=:1 export XAUTHORITY=/root/.Xauthority touch $XAUTHORITY xauth generate :1 . trusted 2>/dev/null || true echo "✅ DISPLAY=$DISPLAY" # ── 3. Start Fluxbox WM ────────────────────────── pkill fluxbox 2>/dev/null || true fluxbox & FLUX_PID=$! echo "✅ Fluxbox started (PID: $FLUX_PID)" sleep 3 # ── 4. خلفية ملوّنة واضحة بعد Fluxbox ──────────── # Fluxbox يُلغي xsetroot — نضعها بعده ونكررها xsetroot -solid "#1a1a2e" 2>/dev/null || true # استخدم convert (ImageMagick) لرسم خلفية ملوّنة مع نص واضح # حتى يعرف الـ AI أن الشاشة حية وليست سوداء convert -size 1920x1080 \ gradient:"#1a1a2e-#16213e" \ -fill "#00d4aa" \ -pointsize 48 \ -gravity Center \ -annotate 0 "Z AI Computer Mode — Ready" \ -fill "#4a90d9" \ -pointsize 28 \ -gravity South \ -annotate 0 "Screen: 1920x1080 | DISPLAY=:1 | $(date '+%H:%M:%S')" \ /tmp/wallpaper.png 2>/dev/null && \ feh --bg-fill /tmp/wallpaper.png 2>/dev/null || \ xsetroot -solid "#1a1a2e" 2>/dev/null || true echo "✅ Wallpaper set" # ── 5. Verify display works ────────────────────── echo "🔍 Testing display..." if xdotool getdisplaygeometry 2>/dev/null; then echo "✅ Display working!" else echo "⚠️ xdotool test failed — continuing anyway" fi # ── 6. Test screenshot ─────────────────────────── scrot -q 80 /tmp/test_shot.png 2>/dev/null && \ echo "✅ Screenshot test: OK" || \ echo "⚠️ scrot test failed" # ── 7. Detect browser ─────────────────────────── if command -v firefox-esr &>/dev/null; then echo "✅ Browser: firefox-esr" BROWSER="firefox-esr" elif command -v firefox &>/dev/null; then echo "✅ Browser: firefox" BROWSER="firefox" elif command -v chromium-browser &>/dev/null; then echo "✅ Browser: chromium-browser" BROWSER="chromium-browser" else echo "⚠️ No browser found" BROWSER="" fi export DEFAULT_BROWSER="$BROWSER" # ── 8. Pre-warm Firefox (اختياري — يسرّع أول فتح) ─ if [ -n "$BROWSER" ]; then $BROWSER --headless --no-sandbox about:blank &>/dev/null & sleep 2 pkill -f "headless" 2>/dev/null || true echo "✅ Browser pre-warmed" fi echo "🚀 Starting Python API on port ${PORT:-7860}..." cd /app exec python3 app.py