v1.8.68: auto-fix X display authorization on startup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
cosmic-frost-8b10
2026-02-28 13:27:02 +00:00
parent 8417507a35
commit 8169e3e137
3 changed files with 35 additions and 1 deletions

34
main.py
View File

@@ -5,14 +5,48 @@ 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()