Replace Web Push and its service worker with page notifications over SSE

This commit is contained in:
Ian Gulliver
2026-10-15 18:34:53 -07:00
parent c7f19f2537
commit a1615693ef
32 changed files with 429 additions and 1175 deletions
-16
View File
@@ -18,7 +18,6 @@ import (
"g.fc.run/misc/byre/internal/agents"
"g.fc.run/misc/byre/internal/api"
"g.fc.run/misc/byre/internal/git"
"g.fc.run/misc/byre/internal/push"
"g.fc.run/misc/byre/internal/store"
"g.fc.run/misc/byre/internal/todo"
)
@@ -26,7 +25,6 @@ import (
type Server struct {
store *store.Store
agents *agents.Manager
notifier *push.Notifier
hub *hub
terminals *terminals
startedAt time.Time
@@ -57,16 +55,9 @@ func New(dataDir string, portFirst int, spa fs.FS) (*Server, error) {
return nil, err
}
s.notifier, err = push.New(s.store, pushWindow)
if err != nil {
s.store.Close()
return nil, fmt.Errorf("start push notifier: %w", err)
}
s.agents = agents.New(s.store, filepath.Join(dataDir, "worktrees"), filepath.Join(dataDir, "leads"), filepath.Join(dataDir, "codex"))
err = s.agents.Recover(context.Background())
if err != nil {
s.notifier.Close()
s.store.Close()
return nil, fmt.Errorf("recover sessions: %w", err)
}
@@ -75,11 +66,8 @@ func New(dataDir string, portFirst int, spa fs.FS) (*Server, error) {
return s, nil
}
const pushWindow = 3 * time.Second
func (s *Server) publish(ev api.Event) {
s.hub.publish(ev)
s.notifier.Observe(ev)
s.agents.Observe(ev)
if (ev.Kind == "task.merged" || ev.Kind == "task.discarded") && ev.TaskId != nil {
s.terminals.close(*ev.TaskId)
@@ -90,15 +78,11 @@ func (s *Server) publish(ev api.Event) {
func (s *Server) Close() error {
s.terminals.closeAll()
s.agents.Close()
s.notifier.Close()
return s.store.Close()
}
func (s *Server) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /sw.js", func(w http.ResponseWriter, r *http.Request) {
http.ServeFileFS(w, r, s.spa, "dist/sw.js")
})
api.HandlerWithOptions(s, api.StdHTTPServerOptions{
BaseRouter: mux,
Middlewares: []api.MiddlewareFunc{s.identify},