package main import ( "fmt" "os" "github.com/godbus/dbus/v5" ) var DATETIME_FORMAT = "02-01-2006 15:03" 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() // https://github.com/godbus/dbus/blob/master/_examples/monitor.go 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) } // Clear terminal fmt.Print("\033[H\033[2J") fmt.Println(textStyle.Render("💬 Listing dbus notifications\n")) c := make(chan *dbus.Message, 10) conn.Eavesdrop(c) for v := range c { if len(v.Body) >= 5 { notification := NewNotification(v) fmt.Println(notification) } } }