""" One-shot health check for the phone bridge, printed as a single JSON line. Answers the question the UI actually needs: is the phone plugged in, is TelecomKz running, and can we talk to its WebView right now? """ import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) import telecom_cdp as T def status(): report = { "connected": False, "device": None, "screenSize": None, "appForeground": False, "webviewReachable": False, "route": None, "metricsSource": T.metrics_source(), "error": None, } try: device = T.get_device() except T.DeviceError as exc: report["error"] = str(exc) return report report["connected"] = True report["device"] = device try: w, h = T.screen_size(device) report["screenSize"] = {"width": w, "height": h} report["appForeground"] = T.app_is_foreground(device) except T.DeviceError as exc: report["error"] = str(exc) return report try: _, target = T.connect(device) report["webviewReachable"] = True report["appForeground"] = True report["route"] = target.get("url") except T.DeviceError as exc: report["error"] = str(exc) return report if __name__ == "__main__": print(json.dumps(status(), ensure_ascii=False))