#!/bin/bash
echo "================================"
echo " 彩云南现·AI短剧工坊 - 桌面版"
echo "================================"
echo ""
echo "正在启动服务..."

cd "$(dirname "$0")"

# Start server in background
node server/drama-server-desktop.js &
SERVER_PID=$!
echo "服务已启动 (PID: $SERVER_PID)"

# Wait for server to be ready
sleep 2

# Open browser
echo "正在打开应用..."
xdg-open http://localhost:3002 2>/dev/null || open http://localhost:3002 2>/dev/null

echo ""
echo "浏览器已打开。按 Ctrl+C 关闭服务。"
echo ""
trap "kill $SERVER_PID 2>/dev/null; echo '服务已关闭'; exit 0" INT TERM
wait $SERVER_PID
