Add X11 daemon with tray status

This commit is contained in:
Thales Maciel 2026-02-06 11:36:45 -03:00
parent 3506770d09
commit a7f50fed75
19 changed files with 1202 additions and 4 deletions

70
internal/audio/record.go Normal file
View file

@ -0,0 +1,70 @@
package audio
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
type Recorder struct {
Input string
}
type RecordResult struct {
WavPath string
TempDir string
}
func (r Recorder) Start(ctx context.Context) (*exec.Cmd, *RecordResult, error) {
tmpdir, err := os.MkdirTemp("", "lel-")
if err != nil {
return nil, nil, err
}
wav := filepath.Join(tmpdir, "mic.wav")
args := []string{"-hide_banner", "-loglevel", "error"}
args = append(args, ffmpegInputArgs(r.Input)...)
args = append(args, "-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le", wav)
cmd := exec.CommandContext(ctx, "ffmpeg", args...)
if err := cmd.Start(); err != nil {
_ = os.RemoveAll(tmpdir)
return nil, nil, err
}
return cmd, &RecordResult{WavPath: wav, TempDir: tmpdir}, nil
}
func WaitWithTimeout(cmd *exec.Cmd, timeout time.Duration) error {
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
select {
case err := <-done:
return err
case <-time.After(timeout):
if cmd.Process != nil {
_ = cmd.Process.Kill()
}
return fmt.Errorf("process timeout after %s", timeout)
}
}
func ffmpegInputArgs(spec string) []string {
if spec == "" {
spec = "pulse:default"
}
kind := spec
name := "default"
if idx := strings.Index(spec, ":"); idx != -1 {
kind = spec[:idx]
name = spec[idx+1:]
}
return []string{"-f", kind, "-i", name}
}