improve daemon's toggle

This commit is contained in:
LeonardoTrapani
2025-08-14 11:30:36 +02:00
parent d28214faad
commit a43adfcf90
3 changed files with 109 additions and 107 deletions
+5 -13
View File
@@ -101,12 +101,8 @@ func (r *Recorder) Stop() error {
if cancel != nil {
cancel()
}
return nil
}
func (r *Recorder) Wait() {
r.wg.Wait()
return nil
}
func (r *Recorder) captureLoop(ctx context.Context, frameCh chan<- AudioFrame, errCh chan<- error) {
@@ -144,16 +140,16 @@ func (r *Recorder) captureLoop(ctx context.Context, frameCh chan<- AudioFrame, e
return
}
r.mu.Lock()
r.cmd = cmd
r.mu.Unlock()
if err := cmd.Start(); err != nil {
r.emitErr(errCh, fmt.Errorf("start pw-record: %w", err))
r.requestCancel()
return
}
r.mu.Lock()
r.cmd = cmd
r.mu.Unlock()
// Log stderr lines to aid diagnostics.
go func() {
scanner := bufio.NewScanner(stderr)
@@ -221,7 +217,6 @@ func (r *Recorder) emitErr(errCh chan<- error, err error) {
select {
case errCh <- err:
default:
// Best-effort; avoid blocking
}
log.Printf("Recording error: %v", err)
}
@@ -246,9 +241,6 @@ func CheckPipeWireAvailable(ctx context.Context) error {
return fmt.Errorf("pw-record not found: %w (install pipewire-tools)", err)
}
// Use a short timeout to avoid hangs on misconfigured systems.
if ctx == nil {
ctx = context.Background()
}
checkCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
cmd := exec.CommandContext(checkCtx, "pw-cli", "info")