|
373 | 373 | "# Install system dependencies only if needed\n", |
374 | 374 | "!command -v mvn >/dev/null 2>&1 && command -v xdpyinfo >/dev/null 2>&1 || (apt-get update && apt-get install -y maven xvfb x11-utils libxext6 libxrender1 libxtst6 libxi6 fonts-dejavu)\n", |
375 | 375 | "\n", |
376 | | - "# Start up a virtual display and test if it works\n", |
377 | | - "print(\"Setting up virtual display...\")\n", |
378 | | - "os.environ[\"DISPLAY\"] = \":99\"\n", |
379 | | - "xvfb_process = subprocess.Popen([\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"])\n", |
380 | | - "\n", |
381 | | - "# Wait a moment for Xvfb to start\n", |
382 | | - "time.sleep(2)\n", |
383 | | - "\n", |
384 | | - "# Test if display is working\n", |
385 | | - "try:\n", |
386 | | - " result = subprocess.run([\"xdpyinfo\"], capture_output=True, text=True, timeout=5)\n", |
387 | | - " display_working = result.returncode == 0\n", |
388 | | - " if display_working:\n", |
389 | | - " print(\"✓ Virtual display working - using interactive mode\")\n", |
390 | | - " ui_mode = 'interactive'\n", |
391 | | - " else:\n", |
392 | | - " print(\"⚠ Virtual display failed - falling back to headless mode\")\n", |
| 376 | + "# Start up a virtual display only if needed\n", |
| 377 | + "if \"DISPLAY\" not in os.environ:\n", |
| 378 | + " print(\"Setting up virtual display...\")\n", |
| 379 | + " os.environ[\"DISPLAY\"] = \":99\"\n", |
| 380 | + " xvfb_process = subprocess.Popen([\"Xvfb\", \":99\", \"-screen\", \"0\", \"1024x768x24\"])\n", |
| 381 | + "\n", |
| 382 | + " # Wait a moment for Xvfb to start\n", |
| 383 | + " time.sleep(2)\n", |
| 384 | + "\n", |
| 385 | + " # Test if display is working\n", |
| 386 | + " try:\n", |
| 387 | + " result = subprocess.run([\"xdpyinfo\"], capture_output=True, text=True, timeout=5)\n", |
| 388 | + " display_working = result.returncode == 0\n", |
| 389 | + " if display_working:\n", |
| 390 | + " print(\"✓ Virtual display working - using interactive mode\")\n", |
| 391 | + " ui_mode = 'interactive'\n", |
| 392 | + " else:\n", |
| 393 | + " print(\"⚠ Virtual display failed - falling back to headless mode\")\n", |
| 394 | + " ui_mode = 'headless'\n", |
| 395 | + " except (subprocess.TimeoutExpired, FileNotFoundError):\n", |
| 396 | + " print(\"⚠ Cannot test display - falling back to headless mode\")\n", |
393 | 397 | " ui_mode = 'headless'\n", |
394 | | - "except (subprocess.TimeoutExpired, FileNotFoundError):\n", |
395 | | - " print(\"⚠ Cannot test display - falling back to headless mode\")\n", |
396 | | - " ui_mode = 'headless'\n", |
| 398 | + "else:\n", |
| 399 | + " print(f\"Display already configured: {os.environ['DISPLAY']}\")\n", |
397 | 400 | "\n", |
398 | 401 | "# Install PyImageJ if not already installed\n", |
399 | 402 | "try:\n", |
|
0 commit comments