-
-
Notifications
You must be signed in to change notification settings - Fork 486
/
notify_dbus.go
38 lines (29 loc) · 935 Bytes
/
notify_dbus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build linux
// +build linux
package notify
import (
"context"
"os"
"github.com/godbus/dbus"
"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/pkg/debug"
)
// Notify displays a desktop notification with dbus.
func Notify(ctx context.Context, subj, msg string) error {
if os.Getenv("GOPASS_NO_NOTIFY") != "" || !config.Bool(ctx, "core.notifications") {
debug.Log("Notifications disabled")
return nil
}
conn, err := dbus.SessionBus()
if err != nil {
debug.Log("DBus failure: %s", err)
return err
}
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(), subj, msg, []string{}, map[string]dbus.Variant{"transient": dbus.MakeVariant(true)}, int32(3000))
if call.Err != nil {
debug.Log("DBus notification failure: %s", call.Err)
return err
}
return nil
}