-
Notifications
You must be signed in to change notification settings - Fork 226
/
monitor.go
38 lines (32 loc) · 1.07 KB
/
monitor.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
package main
import (
"fmt"
"os"
"github.com/godbus/dbus/v5"
)
func main() {
conn, err := dbus.ConnectSessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
os.Exit(1)
}
defer conn.Close()
rules := []string{
"type='signal',member='Notify',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications'",
"type='method_call',member='Notify',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications'",
"type='method_return',member='Notify',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications'",
"type='error',member='Notify',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications'",
}
var flag uint = 0
call := conn.BusObject().Call("org.freedesktop.DBus.Monitoring.BecomeMonitor", 0, rules, flag)
if call.Err != nil {
fmt.Fprintln(os.Stderr, "Failed to become monitor:", call.Err)
os.Exit(1)
}
c := make(chan *dbus.Message, 10)
conn.Eavesdrop(c)
fmt.Println("Monitoring notifications")
for v := range c {
fmt.Println(v)
}
}