fix closing of bus daemon connection on close
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/leonardotrapani/hyprvoice/internal/bus"
|
"github.com/leonardotrapani/hyprvoice/internal/bus"
|
||||||
"github.com/leonardotrapani/hyprvoice/internal/notify"
|
"github.com/leonardotrapani/hyprvoice/internal/notify"
|
||||||
@@ -120,6 +121,12 @@ func (d *Daemon) Run() error {
|
|||||||
d.cancel()
|
d.cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Close the listener when context is done
|
||||||
|
go func() {
|
||||||
|
<-d.ctx.Done()
|
||||||
|
ln.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
log.Printf("Daemon started, listening on socket")
|
log.Printf("Daemon started, listening on socket")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -155,13 +162,13 @@ func (d *Daemon) handle(c net.Conn) {
|
|||||||
switch cmd {
|
switch cmd {
|
||||||
case 't':
|
case 't':
|
||||||
d.toggle()
|
d.toggle()
|
||||||
|
fmt.Fprint(c, "OK toggled\n")
|
||||||
case 's':
|
case 's':
|
||||||
status := d.Status()
|
status := d.Status()
|
||||||
fmt.Fprintf(c, "STATUS recording=%s\n", status)
|
fmt.Fprintf(c, "STATUS recording=%s\n", status)
|
||||||
case 'v':
|
case 'v':
|
||||||
fmt.Fprintf(c, "STATUS proto=%s\n", bus.ProtoVer)
|
fmt.Fprintf(c, "STATUS proto=%s\n", bus.ProtoVer)
|
||||||
case 'q':
|
case 'q':
|
||||||
log.Printf("Shutdown requested")
|
|
||||||
fmt.Fprint(c, "OK quitting\n")
|
fmt.Fprint(c, "OK quitting\n")
|
||||||
d.cancel()
|
d.cancel()
|
||||||
default:
|
default:
|
||||||
@@ -178,7 +185,7 @@ func (d *Daemon) toggle() {
|
|||||||
|
|
||||||
switch d.status {
|
switch d.status {
|
||||||
case Idle:
|
case Idle:
|
||||||
ctx, cancel := context.WithCancel(d.ctx)
|
ctx, cancel := context.WithTimeout(d.ctx, 5*time.Minute)
|
||||||
p := pipeline.New()
|
p := pipeline.New()
|
||||||
d.pipeline = p
|
d.pipeline = p
|
||||||
d.pipelineCancel = cancel
|
d.pipelineCancel = cancel
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (p *pipeline) run(ctx context.Context, statusCh chan<- Status) {
|
|||||||
// Recording phase
|
// Recording phase
|
||||||
select {
|
select {
|
||||||
case <-time.After(2 * time.Second):
|
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
|
statusCh <- Transcribing
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
log.Printf("Pipeline: Stopped during recording")
|
log.Printf("Pipeline: Stopped during recording")
|
||||||
|
|||||||
Reference in New Issue
Block a user