Files
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

61 lines
2.3 KiB
Python

"""Apps interface — install and launch apps from the cua-sandbox-apps catalog."""
from __future__ import annotations
from cua_sandbox.interfaces.shell import CommandResult
from cua_sandbox.transport.base import Transport
class Apps:
"""Install and launch cataloged applications inside the sandbox."""
def __init__(self, transport: Transport, os_type: str):
self._t = transport
self._os_type = os_type
async def install(self, app_id: str) -> CommandResult:
"""Install an app by its catalog ID (e.g. ``"unity"``, ``"godot-engine"``)."""
from cua_sandbox.builder.executor import _find_app_install_script
script = _find_app_install_script(app_id, self._os_type)
if script is None:
return CommandResult(
stdout="",
returncode=1,
stderr=f"No install script for '{app_id}' on {self._os_type}. "
f"Install cua-sandbox-apps or run 'cua-sandbox-apps generate'.",
)
result = await self._t.send(
"run_command", command=f"bash -c {_sh_quote(script)}", timeout=900
)
if isinstance(result, dict):
return CommandResult(
stdout=result.get("stdout", ""),
stderr=result.get("stderr", ""),
returncode=result.get("return_code", result.get("returncode", -1)),
)
return CommandResult(
stdout=getattr(result, "stdout", ""),
stderr=getattr(result, "stderr", ""),
returncode=getattr(result, "returncode", -1),
)
async def launch(self, app_id: str) -> CommandResult:
"""Launch a previously-installed app by its catalog ID."""
from cua_sandbox.builder.executor import _find_app_launch_script
script = _find_app_launch_script(app_id, self._os_type)
if script is None:
return CommandResult(
stdout="",
returncode=1,
stderr=f"No launch script for '{app_id}' on {self._os_type}.",
)
result = await self._t.pty_create(command=f"bash -c {_sh_quote(script)}")
pid = result.get("pid") if isinstance(result, dict) else None
return CommandResult(stdout=str(pid or ""), stderr="", returncode=0)
def _sh_quote(s: str) -> str:
return "'" + s.replace("'", "'\\''") + "'"