소스 검색

Refetch Init after EventConfigChanged for live UI updates

Co-authored-by: Cursor <cursoragent@cursor.com>
jamesread 1 개월 전
부모
커밋
24e02e674f
1개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 26 1
      frontend/js/websocket.js

+ 26 - 1
frontend/js/websocket.js

@@ -50,6 +50,27 @@ async function reconnectWebsocket () {
   }, RECONNECT_DELAY_MS)
 }
 
+async function refreshInitAfterConfigChange () {
+  if (!window.client) {
+    return
+  }
+
+  try {
+    window.initResponse = await window.client.init({})
+
+    if (typeof window.updateHeaderFromInit === 'function') {
+      window.updateHeaderFromInit()
+    }
+  } catch (err) {
+    console.error('Failed to refresh config from server after EventConfigChanged:', err)
+  }
+}
+
+async function handleConfigChangedEvent (j) {
+  await refreshInitAfterConfigChange()
+  window.dispatchEvent(j)
+}
+
 function handleEvent (msg) {
   const typeName = msg.event.value.$typeName.replace('olivetin.api.v1.', '')
 
@@ -57,8 +78,12 @@ function handleEvent (msg) {
   j.payload = msg.event.value
 
   switch (typeName) {
-    case 'EventOutputChunk':
     case 'EventConfigChanged':
+      handleConfigChangedEvent(j).catch((err) => {
+        console.error('EventConfigChanged handler failed:', err)
+      })
+      break
+    case 'EventOutputChunk':
     case 'EventEntityChanged':
       window.dispatchEvent(j)
       break