Files
bjarneo--cliamp/luaplugin/api_notify.go
T
wehub-resource-sync ead81af521
CI / go (push) Waiting to run
CI / build (darwin, macos-14) (push) Waiting to run
CI / build (windows, windows-2025) (push) Waiting to run
Deploy to GitHub Pages / deploy (push) Failing after 0s
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

35 lines
862 B
Go

package luaplugin
import (
"os/exec"
lua "github.com/yuin/gopher-lua"
)
// registerNotifyAPI adds cliamp.notify(title, body) which sends a desktop
// notification via notify-send. Safe alternative to os.execute for this
// specific use case.
func registerNotifyAPI(L *lua.LState, cliamp *lua.LTable, logger *pluginLogger, pluginName string) {
L.SetField(cliamp, "notify", L.NewFunction(func(L *lua.LState) int {
title := L.CheckString(1)
body := L.OptString(2, "")
args := []string{title}
if body != "" {
args = append(args, body)
}
path, err := exec.LookPath("notify-send")
if err != nil {
logger.log(pluginName, "warn", "notify-send not found: %v", err)
return 0
}
cmd := exec.Command(path, args...)
if err := cmd.Run(); err != nil {
logger.log(pluginName, "error", "notify-send failed: %v", err)
}
return 0
}))
}