Files
support-agent/support_agent/main.py
T
2026-04-21 23:38:29 +08:00

59 lines
1.7 KiB
Python

import signal
import sys
import threading
from .config import load_config
from .screenshot import ScreenshotCapture
from .ai_client import AIClient
from .overlay import OverlayWindow
from .hotkey import HotkeyManager
class SupportAgent:
def __init__(self) -> None:
self._cfg = load_config()
self._overlay = OverlayWindow(self._cfg.overlay)
self._screenshot = ScreenshotCapture(self._cfg.screenshot)
self._ai = AIClient(self._cfg.ai)
self._hotkeys = HotkeyManager(
cfg=self._cfg.hotkeys,
on_capture=self._on_capture,
on_toggle=self._overlay.toggle,
)
self._analyzing = False
def _on_capture(self) -> None:
if self._analyzing:
return
threading.Thread(target=self._capture_and_analyze, daemon=True).start()
def _capture_and_analyze(self) -> None:
self._analyzing = True
try:
self._overlay.set_loading()
image_path = self._screenshot.capture()
self._ai.analyze_sync(image_path, self._overlay.append_text)
except Exception as e:
self._overlay.append_text(f"\n\n⚠ 错误:{e}")
finally:
self._analyzing = False
def run(self) -> None:
self._hotkeys.start()
print("support-agent 已启动")
print(f" 截图分析: {self._cfg.hotkeys.capture}")
print(f" 显示/隐藏: {self._cfg.hotkeys.toggle}")
print("按 Ctrl+C 退出")
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = self._overlay.app
exit_code = app.exec()
sys.exit(exit_code)
def main() -> None:
SupportAgent().run()
if __name__ == "__main__":
main()