From 7ed9ea190073e424d371de1d376f944673273969 Mon Sep 17 00:00:00 2001 From: LeonardoTrapani Date: Tue, 12 Aug 2025 19:55:37 +0200 Subject: [PATCH] fix closing of bus daemon connection on close --- internal/daemon/daemon.go | 11 +++++++++-- internal/pipeline/pipeline.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 538e0fb..92755ac 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -10,6 +10,7 @@ import ( "os/signal" "sync" "syscall" + "time" "github.com/leonardotrapani/hyprvoice/internal/bus" "github.com/leonardotrapani/hyprvoice/internal/notify" @@ -120,6 +121,12 @@ func (d *Daemon) Run() error { d.cancel() }() + // Close the listener when context is done + go func() { + <-d.ctx.Done() + ln.Close() + }() + log.Printf("Daemon started, listening on socket") for { @@ -155,13 +162,13 @@ func (d *Daemon) handle(c net.Conn) { switch cmd { case 't': d.toggle() + fmt.Fprint(c, "OK toggled\n") case 's': status := d.Status() fmt.Fprintf(c, "STATUS recording=%s\n", status) case 'v': fmt.Fprintf(c, "STATUS proto=%s\n", bus.ProtoVer) case 'q': - log.Printf("Shutdown requested") fmt.Fprint(c, "OK quitting\n") d.cancel() default: @@ -178,7 +185,7 @@ func (d *Daemon) toggle() { switch d.status { case Idle: - ctx, cancel := context.WithCancel(d.ctx) + ctx, cancel := context.WithTimeout(d.ctx, 5*time.Minute) p := pipeline.New() d.pipeline = p d.pipelineCancel = cancel diff --git a/internal/pipeline/pipeline.go b/internal/pipeline/pipeline.go index 134013f..e2516da 100644 --- a/internal/pipeline/pipeline.go +++ b/internal/pipeline/pipeline.go @@ -53,7 +53,7 @@ func (p *pipeline) run(ctx context.Context, statusCh chan<- Status) { // Recording phase select { case <-time.After(2 * time.Second): - log.Printf("Pipeline: Recording complete, waiting for injection") + log.Printf("Pipeline: TODO start recording, and on first chunk set transcribing and start streaming with Whisper") statusCh <- Transcribing case <-ctx.Done(): log.Printf("Pipeline: Stopped during recording")