Bound notification delivery and expansion

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-09 14:38:02 -04:00
committed by Brandon McGinty
parent 4497d41077
commit d64e5125dd
4 changed files with 43 additions and 12 deletions
+17 -10
View File
@@ -47,8 +47,10 @@ func do_list_devices() {
show_devs("Inputs:", idevs)
}
const notificationQueueSize = 32
func setup_notify_runner(notify_command string) chan []string {
t := make(chan []string)
t := make(chan []string, notificationQueueSize)
var do_nothing = false
var err error
if err != nil {
@@ -57,23 +59,28 @@ func setup_notify_runner(notify_command string) chan []string {
do_nothing = true
}
go func(events chan []string, cmd_template string, dummy bool) {
for {
event := <-events
for event := range events {
if !dummy {
t := string(cmd_template)
t = strings.ReplaceAll(t, "%event", shellescape.Quote(event[0]))
t = strings.ReplaceAll(t, "%who", shellescape.Quote(event[1]))
t = strings.ReplaceAll(t, "%what", shellescape.Quote(event[2]))
cmd := "/bin/sh"
args := []string{"-c", t}
args := []string{"-c", expandNotification(cmd_template, event)}
x := exec.Command(cmd, args...)
x.Run()
} //if we actually have a command to run
} //for
}
}
}(t, notify_command, do_nothing)
return t
}
// expandNotification replaces placeholders in one pass so text supplied for
// one field cannot cause another placeholder to be expanded recursively.
func expandNotification(template string, event []string) string {
return strings.NewReplacer(
"%event", shellescape.Quote(event[0]),
"%who", shellescape.Quote(event[1]),
"%what", shellescape.Quote(event[2]),
).Replace(template)
}
func setup_fifo(fn string) (chan string, error) {
t := make(chan string)
if fn == "" {