From bef6bc659acebaa33b7c5404a81abf35c6617842 Mon Sep 17 00:00:00 2001 From: andreafa Date: Thu, 4 Feb 2021 08:11:15 +0000 Subject: [PATCH] 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. --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7af98b1..2ace3f0 100644 --- a/main.go +++ b/main.go @@ -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 == "" {