Fix cli unload (-u) and add status check option (-c).

The findModule method in module.go requires a valid paClient to be
populated in the context object.
Added logging if unloadSupressor fails when called via the -u CLI flag.
Adding a check CLI flag gives more flexibility when implementing
scripts/CLI workflows.
pull/91/head
andreafa 3 years ago
parent 47d8188b3a
commit bef6bc659a

@ -49,6 +49,7 @@ func main() {
var loadOutput bool
var threshold int
var list bool
var check bool
flag.IntVar(&pulsepid, "removerlimit", -1, "for internal use only")
flag.BoolVar(&setcap, "setcap", false, "for internal use only")
@ -58,6 +59,7 @@ func main() {
flag.BoolVar(&unload, "u", false, "Unload supressor")
flag.IntVar(&threshold, "t", -1, "Voice activation threshold")
flag.BoolVar(&list, "l", false, "List available PulseAudio devices")
flag.BoolVar(&check, "c", false, "Check supressor status")
flag.Parse()
if setcap {
@ -107,6 +109,15 @@ func main() {
os.Exit(1)
}
ctx.paClient = paClient
if check {
if supressorState(&ctx) == loaded {
os.Exit(0)
}
os.Exit(1)
}
if list {
fmt.Println("Sources:")
sources := getSources(paClient)
@ -133,12 +144,15 @@ func main() {
}
if unload {
unloadSupressor(&ctx)
err := unloadSupressor(&ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error unloading PulseAudio Module: %+v\n", err)
os.Exit(1)
}
os.Exit(0)
}
if loadInput {
ctx.paClient = paClient
sources := getSources(paClient)
if sinkName == "" {
@ -165,7 +179,6 @@ func main() {
}
if loadOutput {
ctx.paClient = paClient
sinks := getSinks(paClient)
if sinkName == "" {

Loading…
Cancel
Save