fix(plugin): use os.popen instead of subprocess for mangohud version

This commit is contained in:
2026-06-28 20:46:42 +08:00
parent 6b2dada082
commit 55bc86874a
+15 -15
View File
@@ -155,26 +155,26 @@ class Plugin:
return self._settings return self._settings
async def check_mangohud(self) -> dict: async def check_mangohud(self) -> dict:
"""RPC: Check if MangoHud is installed. Returns {installed: bool, path: str, version: str}.""" """RPC: Check if MangoHud is installed."""
import subprocess as sp
import os import os
try: try:
# Use the full path to avoid PATH issues path = "/usr/bin/mangohud"
mangohud_path = "/usr/bin/mangohud" exists = os.path.exists(path)
if not os.path.exists(mangohud_path): if not exists:
# Fall back to which
r = sp.run(["which", "mangohud"], capture_output=True, text=True, timeout=5)
if r.returncode != 0:
return {"installed": False, "path": "", "version": ""} return {"installed": False, "path": "", "version": ""}
mangohud_path = r.stdout.strip()
# Get version using the full path # Get version using os.popen (more reliable than subprocess in some envs)
v = sp.run([mangohud_path, "--version"], capture_output=True, text=True, timeout=5) version = ""
version = v.stdout.strip() if v.returncode == 0 else "" try:
if version and "-" in version: with os.popen(f"{path} --version 2>/dev/null") as pipe:
version = version.split("-")[0] v = pipe.read().strip()
if v and "-" in v:
v = v.split("-")[0]
version = v
except:
pass
return {"installed": True, "path": mangohud_path, "version": version or ""} return {"installed": True, "path": path, "version": version}
except Exception as e: except Exception as e:
return {"installed": False, "path": "", "version": "", "error": str(e)} return {"installed": False, "path": "", "version": "", "error": str(e)}