vendor/github.com/gen2brain/beeep/notify_unix_nodbus.go
46 lines · 976 bytes
1//go:build (linux && nodbus) || (freebsd && nodbus) || (netbsd && nodbus) || (openbsd && nodbus) || illumos
2// +build linux,nodbus freebsd,nodbus netbsd,nodbus openbsd,nodbus illumos
3
4package beeep
5
6import (
7 "errors"
8 "os/exec"
9)
10
11// Notify sends desktop notification.
12func Notify(title, message, appIcon string) error {
13 appIcon = pathAbs(appIcon)
14
15 cmd := func() error {
16 send, err := exec.LookPath("sw-notify-send")
17 if err != nil {
18 send, err = exec.LookPath("notify-send")
19 if err != nil {
20 return err
21 }
22 }
23
24 c := exec.Command(send, title, message, "-i", appIcon)
25 return c.Run()
26 }
27
28 knotify := func() error {
29 send, err := exec.LookPath("kdialog")
30 if err != nil {
31 return err
32 }
33 c := exec.Command(send, "--title", title, "--passivepopup", message, "10", "--icon", appIcon)
34 return c.Run()
35 }
36
37 err := cmd()
38 if err != nil {
39 e := knotify()
40 if e != nil {
41 return errors.New("beeep: " + err.Error() + "; " + e.Error())
42 }
43 }
44
45 return nil
46}