Files
DDSRem 2de976f6b3 Merge pull request #7050 from DDSRem-Dev/codex-comment-migration
docs: 统一全项目中文注释和结构化契约说明
2026-10-17 19:26:29 +08:00

63 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
虚拟显示适配器及旧 DisplayHelper 兼容入口。
"""
from __future__ import annotations
from importlib import import_module
from typing import Any
from app.foundation.singleton import Singleton
from app.runtime.log import logger
from app.runtime.resources import (
acquire_managed_resource,
stop_managed_resource,
)
DISPLAY_CAPABILITY_ID = "host.display"
class DisplayHelper(metaclass=Singleton):
"""
保留旧构造 API,并把资源所有权委托给 host.display 能力。
"""
def __init__(self) -> None:
"""
显式构造旧门面时激活虚拟显示,失败保持旧 API 的日志语义。
"""
try:
acquire_managed_resource(
DISPLAY_CAPABILITY_ID,
reason="legacy_display_helper",
retry=True,
)
except Exception as error:
logger.error("DisplayHelper init error: %s", error)
def stop(self) -> None:
"""
停止已激活的虚拟显示;未配置 Runtime 时保持幂等。
"""
stop_managed_resource(
DISPLAY_CAPABILITY_ID,
reason="legacy_display_helper_stop",
)
__all__ = ["DISPLAY_CAPABILITY_ID", "DisplayHelper", "VirtualDisplayResource"]
def __getattr__(name: str) -> Any:
"""
按需公开资源实现,普通兼容导入不加载显示后端。
"""
if name != "VirtualDisplayResource":
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
value = getattr(
import_module("app.adapters.system.display.resource"),
"VirtualDisplayResource",
)
globals()[name] = value
return value