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:
34
main.py
34
main.py
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user