feat: テレメトリ機能を追加し、アプリの起動・終了時にイベントを送信するように変更

This commit is contained in:
misyaguziya
2026-01-08 09:16:18 +09:00
parent 4eb61fa4b7
commit d157dc8b7b
12 changed files with 603 additions and 44 deletions

View File

@@ -460,14 +460,20 @@ class Main:
"""Read lines from stdin, parse JSON and enqueue requests.
Uses blocking readline but honors stop via _stop_event checked between reads.
EOF on stdin indicates the frontend has closed; trigger app_closed event.
"""
while not self._stop_event.is_set():
try:
line = sys.stdin.readline()
if not line:
# EOF reached; sleep briefly and re-check stop event
time.sleep(0.1)
continue
# EOF reached - frontend has closed connection
# Trigger telemetry shutdown to send app_closed event
printLog("Frontend disconnected (stdin EOF)", {"event": "frontend_closed"})
try:
self.controller.shutdown()
except Exception:
errorLogging()
break
received_data = json.loads(line.strip())
if received_data:
@@ -584,6 +590,12 @@ class Main:
Args:
wait: maximum seconds to wait for threads to join.
"""
# Controller 経由でシャットダウンmodel.shutdown() → telemetry.shutdown() が呼ばれる)
try:
self.controller.shutdown()
except Exception:
errorLogging()
self._stop_event.set()
# give threads a chance to exit
start = time.time()