src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

mic.go (532B)


      1 package mic
      2 
      3 import (
      4 	"context"
      5 	"fmt"
      6 	"os/exec"
      7 	"strings"
      8 )
      9 
     10 type Block struct{}
     11 
     12 func New() *Block {
     13 	return &Block{}
     14 }
     15 
     16 func (b *Block) Name() string {
     17 	return "mic"
     18 }
     19 
     20 func (b *Block) Render(ctx context.Context) (string, error) {
     21 	out, err := exec.CommandContext(
     22 		ctx, "pactl", "get-source-mute", "@DEFAULT_SOURCE@",
     23 	).Output()
     24 	if err != nil {
     25 		return "", fmt.Errorf("exec pactl failed: %v", err)
     26 	}
     27 
     28 	if strings.Contains(string(out), "yes") {
     29 		return fmt.Sprintf(""), nil
     30 	}
     31 
     32 	return fmt.Sprintf(" OPEN"), nil
     33 }