一旦フロントエンドまで接続
This commit is contained in:
@@ -49,12 +49,18 @@ class Controller:
|
||||
def setRun(self, run:Callable[[int, str, Any], None]) -> None:
|
||||
self.run = run
|
||||
|
||||
def shutdown(self) -> None:
|
||||
"""Shutdown controller and model (including telemetry)."""
|
||||
def shutdown(self, *args, **kwargs) -> dict:
|
||||
"""Shutdown controller and model (including telemetry).
|
||||
|
||||
Returns:
|
||||
dict with status 200 and result True on success.
|
||||
"""
|
||||
try:
|
||||
model.shutdown()
|
||||
return {"status": 200, "result": True}
|
||||
except Exception:
|
||||
errorLogging()
|
||||
return {"status": 500, "result": False}
|
||||
|
||||
# response functions
|
||||
def connectedNetwork(self) -> None:
|
||||
|
||||
@@ -129,6 +129,8 @@ mapping = {
|
||||
|
||||
"/run/send_text_overlay": {"status": True, "variable":controller.sendTextOverlay},
|
||||
|
||||
"/run/shutdown": {"status": True, "variable":controller.shutdown},
|
||||
|
||||
"/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage},
|
||||
|
||||
"/run/update_software": {"status": True, "variable":controller.updateSoftware},
|
||||
@@ -460,20 +462,14 @@ 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 - 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
|
||||
# EOF reached; sleep briefly and re-check stop event
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
received_data = json.loads(line.strip())
|
||||
|
||||
if received_data:
|
||||
|
||||
Reference in New Issue
Block a user