| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package beeep |
| 5 |
|
| 6 |
import ( |
| 7 |
"errors" |
| 8 |
"os/exec" |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
func 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 |
} |