2021-11-24 19:36:36 +00:00
|
|
|
package main
|
|
|
|
|
2022-05-11 20:24:12 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2021-11-24 19:36:36 +00:00
|
|
|
|
2022-05-11 20:24:12 +00:00
|
|
|
"github.com/godbus/dbus/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newSystemBusConn(ctx context.Context) (*dbus.Conn, error) {
|
2021-11-24 19:36:36 +00:00
|
|
|
// Connect to dbus session bus
|
2022-05-11 20:24:12 +00:00
|
|
|
conn, err := dbus.SystemBusPrivate(dbus.WithContext(ctx))
|
2021-11-24 19:36:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = conn.Auth(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = conn.Hello()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return conn, nil
|
|
|
|
}
|
|
|
|
|
2022-05-11 20:24:12 +00:00
|
|
|
func newSessionBusConn(ctx context.Context) (*dbus.Conn, error) {
|
2021-11-24 19:36:36 +00:00
|
|
|
// Connect to dbus session bus
|
2022-05-11 20:24:12 +00:00
|
|
|
conn, err := dbus.SessionBusPrivate(dbus.WithContext(ctx))
|
2021-11-24 19:36:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = conn.Auth(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = conn.Hello()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return conn, nil
|
|
|
|
}
|