game launcher updates.
This commit is contained in:
@@ -23,6 +23,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
INSTALL_GAME_RUNNER = Path("/home/stormux/.local/.functions/install_game.sh")
|
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)
|
@dataclass(frozen=True)
|
||||||
@@ -94,6 +96,29 @@ def build_game_actions(entry):
|
|||||||
actions.append(("Install", build_game_install_command(entry)))
|
actions.append(("Install", build_game_install_command(entry)))
|
||||||
return actions
|
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:
|
class VoicedMenu:
|
||||||
def __init__(self, title="Stormux Game Menu"):
|
def __init__(self, title="Stormux Game Menu"):
|
||||||
self.title = title
|
self.title = title
|
||||||
@@ -390,11 +415,14 @@ class VoicedMenu:
|
|||||||
self.speechClient = None
|
self.speechClient = None
|
||||||
|
|
||||||
action = "disable" if isActive else "enable"
|
action = "disable" if isActive else "enable"
|
||||||
command = f"sudo /home/stormux/.local/bin/stormux_service_state.sh {action} {serviceName}"
|
result = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.system(command)
|
result = run_service_action(action, serviceName)
|
||||||
print(f"{friendlyName} {action}d successfully")
|
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:
|
except Exception as e:
|
||||||
print(f"Error {action}ing {friendlyName}: {e}")
|
print(f"Error {action}ing {friendlyName}: {e}")
|
||||||
|
|
||||||
@@ -407,19 +435,21 @@ class VoicedMenu:
|
|||||||
curses.cbreak()
|
curses.cbreak()
|
||||||
self.stdscr.keypad(True)
|
self.stdscr.keypad(True)
|
||||||
|
|
||||||
# Announce the action
|
if result is not None and result.returncode == 0:
|
||||||
self.speak(f"{friendlyName} {action}d")
|
self.speak(f"{friendlyName} {action}d")
|
||||||
|
|
||||||
# Update the menu with the new service status
|
# Update the menu with the new service status
|
||||||
self.update_service_menu_items()
|
self.update_service_menu_items()
|
||||||
|
|
||||||
# Update Bluetooth menu items if Bluetooth service was toggled
|
# Update Bluetooth menu items if Bluetooth service was toggled
|
||||||
if friendlyName == "Bluetooth":
|
if friendlyName == "Bluetooth":
|
||||||
self.update_bluetooth_menu_items()
|
self.update_bluetooth_menu_items()
|
||||||
|
|
||||||
# Update Media menu items if DLNA Server was toggled
|
# Update Media menu items if DLNA Server was toggled
|
||||||
if friendlyName == "D L N A Server":
|
if friendlyName == "D L N A Server":
|
||||||
self.update_media_menu_items()
|
self.update_media_menu_items()
|
||||||
|
else:
|
||||||
|
self.speak(f"Could not {action} {friendlyName}. Check service action log.")
|
||||||
|
|
||||||
# Redraw the menu
|
# Redraw the menu
|
||||||
self.draw_menu()
|
self.draw_menu()
|
||||||
|
|||||||
Reference in New Issue
Block a user