"""Transport selection is separate from automatic/manual approval policy.""" VISUAL = "visual" PROTOCOL = "protocol" INVALID = "invalid" def normalize_reply_transport(value): # Only an absent setting receives the visual default (callers pass VISUAL). # Unknown or damaged explicit values must never activate another sender. if isinstance(value, str) and value.strip().lower() in (VISUAL, PROTOCOL): return value.strip().lower() return INVALID def transport_start_blocker(value): """Return a diagnostic for an unavailable sender; None means visual is supported.""" transport = normalize_reply_transport(value) if transport == VISUAL: return None if transport == INVALID: return { "status": "invalid_transport", "label": "回复通道配置无效", "message": "请选择视觉模式或协议模式后重新启动。", "canSend": False, } from wxwork_protocol_probe import probe_installed_client report = probe_installed_client() if protocol_ready(report): return None report["canSend"] = False return report def protocol_ready(report): from wecom_native_builds import BUILDS from wecom_native_evidence import send_authorized if not isinstance(report, dict): return False profile = next((b for b in BUILDS if b.adapter_id == report.get("nativeAdapter")), None) proven = bool(profile and (profile.verified or (report.get("clientSha256") == profile.sha256 and report.get("localSendVerified") is True and send_authorized(profile, report.get("nativeAccount"))))) return bool(proven and report.get("status") == "native_ready" and all(report.get(k) is True for k in ("canSend", "loginVerified", "adapterInstalled", "sendVerified", "receiptVerified", "databaseReady"))) def queue_path_for_transport(value=None, *, root=None): import json from runtime_paths import application_data_dir from pathlib import Path root = Path(root) if root is not None else application_data_dir() if value is None: try: value = json.loads((root / "app_settings.json").read_text(encoding="utf-8")).get("reply_transport", VISUAL) except (OSError, ValueError, AttributeError): value = VISUAL return root / ("pending_replies.protocol.json" if normalize_reply_transport(value) == PROTOCOL else "pending_replies.json")