Files
thinlauncher/launcher/actions.py
2026-08-25 14:27:22 +01:00

61 lines
2.0 KiB
Python

import subprocess
import shutil
class ActionDispatcher:
def dispatch(self, service_type, target):
print(f"Executing action -> Type: {service_type}, Target: {target}")
if service_type == "browser":
self._launch_app_browser(target)
elif service_type == "rdp":
## Refactor required to pass 'config' through to this level
self._launch_xfreerdp(config)
elif service_type == "command":
self._run_command(target.split())
elif service_type == "power":
self._handle_power_action(target)
else:
print(f"Service type: {service_type}, not known")
def _launch_app_browser(self, url):
browser_candidates = [
"chromium",
"chromium-browser",
"brave-browser",
"google-chrome",
"microsoft-edge",
"vivaldi"
]
browser_bin = None
for candidate in browser_candidates:
if shutil.which(candidate):
browser_bin = candidate
break
if not browser_bin:
print("Error: No supported chromium based browser found in PATH,")
return
cmd = [browser_bin, f"--app={url}", "--start-maximized", "--incognito"]
print(f"Launching browser command: {' '.join(cmd)}")
self._run_command(cmd)
def _launch_xfreerdp(self, config):
# Read config and build xfreerdp command before passing to _run_command
return
def _handle_power_action(self, action):
if action == "shutdown":
print("Initiating system shutdown")
self._run_command(["systemctl", "poweroff"])
elif action == "reboot":
print("Initiating system reboot...")
self._run_command(["systemctl", "reboot"])
else:
print(f"Unknown power action: {action}")
def _run_command(self, cmd):
try:
subprocess.Popen(cmd)
except Exception as e:
print(f"Failed to execute cmd: {cmd}: {e}")