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 loadOutput bool
var threshold int var threshold int
var list bool var list bool
var check bool
flag.IntVar(&pulsepid, "removerlimit", -1, "for internal use only") flag.IntVar(&pulsepid, "removerlimit", -1, "for internal use only")
flag.BoolVar(&setcap, "setcap", false, "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.BoolVar(&unload, "u", false, "Unload supressor")
flag.IntVar(&threshold, "t", -1, "Voice activation threshold") flag.IntVar(&threshold, "t", -1, "Voice activation threshold")
flag.BoolVar(&list, "l", false, "List available PulseAudio devices") flag.BoolVar(&list, "l", false, "List available PulseAudio devices")
flag.BoolVar(&check, "c", false, "Check supressor status")
flag.Parse() flag.Parse()
if setcap { if setcap {
@ -107,6 +109,15 @@ func main() {
os.Exit(1) os.Exit(1)
} }
ctx.paClient = paClient
if check {
if supressorState(&ctx) == loaded {
os.Exit(0)
}
os.Exit(1)
}
if list { if list {
fmt.Println("Sources:") fmt.Println("Sources:")
sources := getSources(paClient) sources := getSources(paClient)
@ -133,12 +144,15 @@ func main() {
} }
if unload { 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) os.Exit(0)
} }
if loadInput { if loadInput {
ctx.paClient = paClient
sources := getSources(paClient) sources := getSources(paClient)
if sinkName == "" { if sinkName == "" {
@ -165,7 +179,6 @@ func main() {
} }
if loadOutput { if loadOutput {
ctx.paClient = paClient
sinks := getSinks(paClient) sinks := getSinks(paClient)
if sinkName == "" { if sinkName == "" {

Loading…
Cancel
Save