Fix sidecar pipe crash on state changes and show logged-in state in settings
The state callback in main_headless.py wrote events to stdout synchronously, so an EINVAL on the Tauri sidecar pipe (Windows) bubbled up through _set_state and tore down engine init and reload_engine. That turned PUT /api/config into a "Failed to fetch" for the user. The print is now pipe-safe and api_server isolates the chained callback so a future misbehaving listener cannot break the engine state machine. Settings also now persists remote.email on login and shows a "Logged in as <email>" indicator with a Log out button when an auth_token is present, instead of leaving the email/password fields blank on reload. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,8 +73,15 @@ class APIServer:
|
||||
original_state_cb = self.controller.on_state_changed
|
||||
|
||||
def on_state_changed(state: str, message: str):
|
||||
# Isolate the upstream callback so a failure there (e.g. a
|
||||
# broken stdout pipe in main_headless) cannot propagate into
|
||||
# _set_state and tear down engine init / reload_engine /
|
||||
# apply_settings request handling.
|
||||
if original_state_cb:
|
||||
original_state_cb(state, message)
|
||||
try:
|
||||
original_state_cb(state, message)
|
||||
except Exception:
|
||||
pass
|
||||
self._broadcast_control({"type": "state_changed", "state": state, "message": message})
|
||||
|
||||
self.controller.on_state_changed = on_state_changed
|
||||
@@ -273,6 +280,7 @@ class APIServer:
|
||||
data = resp.json()
|
||||
ctrl.config.set('remote.auth_token', data.get('token', ''))
|
||||
ctrl.config.set('remote.server_url', req.server_url)
|
||||
ctrl.config.set('remote.email', req.email)
|
||||
return {"status": "ok", "token": data.get('token', '')}
|
||||
else:
|
||||
raise HTTPException(status_code=resp.status_code, detail=resp.text)
|
||||
|
||||
Reference in New Issue
Block a user