From 6761f72338e38b9b02fb964f99c9ba79a4d33e4a Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 21 Apr 2026 15:20:37 -0400 Subject: [PATCH] game launcher updates. --- home/stormux/.local/bin/game_launcher.py | 56 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/home/stormux/.local/bin/game_launcher.py b/home/stormux/.local/bin/game_launcher.py index c606863..cca7dcd 100755 --- a/home/stormux/.local/bin/game_launcher.py +++ b/home/stormux/.local/bin/game_launcher.py @@ -23,6 +23,8 @@ from pathlib import Path INSTALL_GAME_RUNNER = Path("/home/stormux/.local/.functions/install_game.sh") +SERVICE_STATE_HELPER = Path("/home/stormux/.local/bin/stormux_service_state.sh") +SERVICE_ACTION_LOG = Path.home() / ".cache" / "stormux" / "service-actions.log" @dataclass(frozen=True) @@ -94,6 +96,29 @@ def build_game_actions(entry): actions.append(("Install", build_game_install_command(entry))) return actions + +def run_service_action(action, serviceName, helper=SERVICE_STATE_HELPER, logPath=SERVICE_ACTION_LOG): + command = ["sudo", "-n", str(helper), action, serviceName] + result = subprocess.run(command, capture_output=True, text=True, check=False) + + logPath = Path(logPath) + logPath.parent.mkdir(parents=True, exist_ok=True) + with logPath.open("a", encoding="utf-8") as logFile: + logFile.write(f"Service action {' '.join(command)} [{time.ctime()}]\n") + logFile.write(f"Return code: {result.returncode}\n") + if result.stdout: + logFile.write("stdout:\n") + logFile.write(result.stdout) + if not result.stdout.endswith("\n"): + logFile.write("\n") + if result.stderr: + logFile.write("stderr:\n") + logFile.write(result.stderr) + if not result.stderr.endswith("\n"): + logFile.write("\n") + + return result + class VoicedMenu: def __init__(self, title="Stormux Game Menu"): self.title = title @@ -390,11 +415,14 @@ class VoicedMenu: self.speechClient = None action = "disable" if isActive else "enable" - command = f"sudo /home/stormux/.local/bin/stormux_service_state.sh {action} {serviceName}" + result = None try: - os.system(command) - print(f"{friendlyName} {action}d successfully") + result = run_service_action(action, serviceName) + if result.returncode == 0: + print(f"{friendlyName} {action}d successfully") + else: + print(f"Error {action}ing {friendlyName}: see {SERVICE_ACTION_LOG}") except Exception as e: print(f"Error {action}ing {friendlyName}: {e}") @@ -407,19 +435,21 @@ class VoicedMenu: curses.cbreak() self.stdscr.keypad(True) - # Announce the action - self.speak(f"{friendlyName} {action}d") + if result is not None and result.returncode == 0: + self.speak(f"{friendlyName} {action}d") - # Update the menu with the new service status - self.update_service_menu_items() + # Update the menu with the new service status + self.update_service_menu_items() - # Update Bluetooth menu items if Bluetooth service was toggled - if friendlyName == "Bluetooth": - self.update_bluetooth_menu_items() + # Update Bluetooth menu items if Bluetooth service was toggled + if friendlyName == "Bluetooth": + self.update_bluetooth_menu_items() - # Update Media menu items if DLNA Server was toggled - if friendlyName == "D L N A Server": - self.update_media_menu_items() + # Update Media menu items if DLNA Server was toggled + if friendlyName == "D L N A Server": + self.update_media_menu_items() + else: + self.speak(f"Could not {action} {friendlyName}. Check service action log.") # Redraw the menu self.draw_menu()