diff --git a/src/go/tsgo/dbus.go b/src/go/tsgo/dbus.go index f576022..897a97e 100644 --- a/src/go/tsgo/dbus.go +++ b/src/go/tsgo/dbus.go @@ -1,12 +1,59 @@ package tsgo -import "github.com/godbus/dbus" +import ( + "errors" + + "github.com/godbus/dbus" + "github.com/godbus/dbus/introspect" +) var dbusConn *dbus.Conn -func initDbus() { - dbusConn, _ = dbus.ConnectSessionBus() - // Add error handling +const intro = ` + + + + ` + introspect.IntrospectDataString + ` + ` + +type dbusHandler int + +func (d dbusHandler) ToggleMute() *dbus.Error { + Ts3Functions.PrintMessage(1, "toggle", PLUGIN_MESSAGE_TARGET_SERVER) // TODO placeholder + return nil +} + +func initDbus() error { + var err error + dbusConn, err = dbus.ConnectSessionBus() + + if err != nil { + return err + } + + err = dbusConn.Export(introspect.Introspectable(intro), "/", "org.freedesktop.DBus.Introspectable") + if err != nil { + return err + } + + err = dbusConn.Export(dbusHandler(1), "/", "org.kapelle.ts3") + if err != nil { + return err + } + + reply, err2 := dbusConn.RequestName("org.kapelle.ts3", dbus.NameFlagDoNotQueue) + if err2 != nil { + return err2 + } + if reply != dbus.RequestNameReplyPrimaryOwner { + return errors.New("name already taken") + } + + return nil +} + +func closeConn() { + dbusConn.Close() } func notifyPoke(from, message string) { diff --git a/src/go/tsgo/tsgo.go b/src/go/tsgo/tsgo.go index c540f3a..3da6aa5 100644 --- a/src/go/tsgo/tsgo.go +++ b/src/go/tsgo/tsgo.go @@ -36,7 +36,7 @@ func Ts3pluginInit() int { //Ts3pluginShutdown shutdown plugin function func Ts3pluginShutdown() { - + closeConn() } /*