2023-09-08 18:00:11 +00:00
|
|
|
//go:build linux
|
|
|
|
|
2023-09-08 13:01:29 +00:00
|
|
|
package hooks
|
2023-09-08 18:00:11 +00:00
|
|
|
|
2023-09-08 13:01:29 +00:00
|
|
|
// Hooks to exececute host system commands
|
2023-09-08 18:00:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/0xAX/notificator"
|
|
|
|
|
|
|
|
"git.blob42.xyz/gomark/gosuki/parsing"
|
|
|
|
"git.blob42.xyz/gomark/gosuki/tree"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hook that sends a system notification using notify-send (Linux).
|
|
|
|
// To enable notification a tag must be presetn in the name with the form: `#tag:notify`
|
|
|
|
// Requires notify-send to be installed
|
|
|
|
func NotifySend(node *tree.Node) error {
|
|
|
|
// if node.Name has a tag of the form #tag:notify
|
|
|
|
|
|
|
|
regex := regexp.MustCompile(parsing.ReNotify)
|
|
|
|
|
|
|
|
if !regex.MatchString(node.Name) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
notify := notificator.New(notificator.Options{
|
|
|
|
AppName: "gosuki",
|
|
|
|
})
|
|
|
|
return notify.Push("new bookmark", node.URL, "", notificator.UR_NORMAL)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init(){
|
|
|
|
regHook(Hook{
|
|
|
|
Name: "notify-send",
|
|
|
|
Func: NotifySend,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|