From dc1281411d1cf6a0d9cfe6f1cb02ea480b8b13ae Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Sun, 28 Jun 2026 07:53:02 +0800 Subject: [PATCH] feat(plugin): add MangoHud status check and config writing to backend --- plugins/decky-vault/main.py | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/plugins/decky-vault/main.py b/plugins/decky-vault/main.py index c420fd6..b3f85a3 100644 --- a/plugins/decky-vault/main.py +++ b/plugins/decky-vault/main.py @@ -53,4 +53,67 @@ class Plugin: """RPC: Set a single setting and persist. Returns updated settings.""" self._settings[key] = value self._write_settings(self._settings) - return self._settings \ No newline at end of file + return self._settings + + async def check_mangohud(self) -> dict: + """RPC: Check if MangoHud is installed. Returns {installed: bool, path: str, version: str}.""" + import subprocess + try: + result = subprocess.run( + ["which", "mangohud"], + capture_output=True, text=True, timeout=5 + ) + if result.returncode == 0: + mangohud_path = result.stdout.strip() + # Get version + version_result = subprocess.run( + ["mangohud", "--version"], + capture_output=True, text=True, timeout=5 + ) + version = version_result.stdout.strip() if version_result.returncode == 0 else "unknown" + return {"installed": True, "path": mangohud_path, "version": version} + else: + return {"installed": False, "path": "", "version": ""} + except Exception as e: + return {"installed": False, "path": "", "version": "", "error": str(e)} + + async def write_mangohud_config(self) -> dict: + """RPC: Write the MangoHud logging config to ~/.config/MangoHud/MangoHud.conf. + Returns {success: bool, path: str, error: str?}.""" + try: + home = os.path.expanduser("~") + config_dir = os.path.join(home, ".config", "MangoHud") + config_path = os.path.join(config_dir, "MangoHud.conf") + os.makedirs(config_dir, exist_ok=True) + + # MangoHud config that enables logging with the metrics we need. + # output_folder is required for logging to work. + # We log to /tmp so the plugin can read it after the session. + config_content = """\ +# DeckyVault MangoHud logging config +output_folder=/tmp +output_file=deckyvault-mangohud.log +log_duration=0 +fps +frame_timing +cpu_power +gpu_power +cpu_temp +gpu_temp +benchmark_percentiles=97,AVG,1,0.1 +""" + with open(config_path, 'w') as f: + f.write(config_content) + + return {"success": True, "path": config_path} + except Exception as e: + return {"success": False, "path": "", "error": str(e)} + + async def get_mangohud_config(self) -> dict: + """RPC: Read the current MangoHud config. Returns {exists: bool, content: str, path: str}.""" + home = os.path.expanduser("~") + config_path = os.path.join(home, ".config", "MangoHud", "MangoHud.conf") + if os.path.exists(config_path): + with open(config_path, 'r') as f: + return {"exists": True, "content": f.read(), "path": config_path} + return {"exists": False, "content": "", "path": config_path} \ No newline at end of file