-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ae69d1
commit 37bf87e
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/godbus/dbus/v5" | ||
) | ||
|
||
func main() { | ||
conn, err := dbus.SessionBus() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err) | ||
os.Exit(1) | ||
} | ||
|
||
var 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) | ||
} | ||
} |