Files
server-manager/main.py
cosmic-frost-8b10 8169e3e137 v1.8.68: auto-fix X display authorization on startup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 13:27:02 +00:00

56 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
ServerManager — GUI application for managing remote servers.
"""
import sys
import os
import subprocess
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def _ensure_display_access():
"""Auto-fix X display authorization for root and non-owner users."""
display = os.environ.get("DISPLAY")
if not display:
# Try common displays
for d in (":0", ":1", ":0.0"):
os.environ["DISPLAY"] = d
display = d
break
try:
subprocess.run(["xhost", "+local:"], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=3)
except (FileNotFoundError, subprocess.TimeoutExpired):
pass
# Fallback: generate xauth cookie if xhost not available
if display:
try:
subprocess.run(["xdpyinfo"], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=3, check=True)
except (FileNotFoundError, subprocess.TimeoutExpired, subprocess.CalledProcessError):
try:
xauth_file = os.path.expanduser("~/.Xauthority")
os.environ.setdefault("XAUTHORITY", xauth_file)
subprocess.run(
["xauth", "generate", display, ".", "trusted"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5
)
except (FileNotFoundError, subprocess.TimeoutExpired):
pass
from gui.app import App
def main():
_ensure_display_access()
app = App()
app.mainloop()
if __name__ == "__main__":
main()