local-tool/: visionA-local desktop app
- M1: Wails shell + Go server + Next.js UI + Mock mode (macOS dmg ready)
- M2: i18n (zh-TW/en) + Settings 4-tab refactor
- M3: Embedded Python 3.12 runtime (python-build-standalone) + KneronPLUS wheels
- M4: Windows Inno Setup script (build on Windows runner)
- M5: Linux AppImage script + udev rule (build on Linux runner)
- M6: ffmpeg (GPL, pending legal review) + yt-dlp bundled
- Lifecycle: watchServer health check, fatal native dialog,
Wails IPC raise endpoint, stale process cleanup
.autoflow/: full PRD / Design Spec / Architecture / Testing docs
(4 rounds tri-party discussion + cross review)
.github/workflows/: macOS / Windows / Linux build CI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package ws
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"visiona-local/server/pkg/logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
func ServerLogsHandler(hub *Hub, broadcaster *logger.Broadcaster) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer conn.Close()
|
|
|
|
client := &Client{Conn: conn, Send: make(chan []byte, 100)}
|
|
sub := &Subscription{Client: client, Room: "server-logs"}
|
|
hub.RegisterSync(sub)
|
|
defer hub.Unregister(sub)
|
|
|
|
// Send buffered recent logs to the newly connected client
|
|
if broadcaster != nil {
|
|
for _, entry := range broadcaster.Recent() {
|
|
data, err := json.Marshal(entry)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
select {
|
|
case client.Send <- data:
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// Read pump — drain incoming messages (close frames)
|
|
go func() {
|
|
defer conn.Close()
|
|
for {
|
|
if _, _, err := conn.ReadMessage(); err != nil {
|
|
break
|
|
}
|
|
}
|
|
}()
|
|
|
|
// Write pump
|
|
for msg := range client.Send {
|
|
if err := conn.WriteMessage(websocket.TextMessage, msg); err != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|