All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m17s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hpkg (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m3s
Test / Flake checks (push) Successful in 1m40s
These packages are highly specific to hakurei and are difficult to use safely from other pieces of code. Their exported symbols are made available until v0.4.0 where they will be removed for #24. Signed-off-by: Ophestra <cat@gensokyo.uk>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package dbus
|
|
|
|
import (
|
|
"hakurei.app/hst"
|
|
)
|
|
|
|
// ProxyPair is an upstream dbus address and a downstream socket path.
|
|
type ProxyPair [2]string
|
|
|
|
// Args returns the xdg-dbus-proxy arguments equivalent of [hst.BusConfig].
|
|
func Args(c *hst.BusConfig, bus ProxyPair) (args []string) {
|
|
argc := 2 + len(c.See) + len(c.Talk) + len(c.Own) + len(c.Call) + len(c.Broadcast)
|
|
if c.Log {
|
|
argc++
|
|
}
|
|
if c.Filter {
|
|
argc++
|
|
}
|
|
|
|
args = make([]string, 0, argc)
|
|
args = append(args, bus[0], bus[1])
|
|
if c.Filter {
|
|
args = append(args, "--filter")
|
|
}
|
|
for _, name := range c.See {
|
|
args = append(args, "--see="+name)
|
|
}
|
|
for _, name := range c.Talk {
|
|
args = append(args, "--talk="+name)
|
|
}
|
|
for _, name := range c.Own {
|
|
args = append(args, "--own="+name)
|
|
}
|
|
for name, rule := range c.Call {
|
|
args = append(args, "--call="+name+"="+rule)
|
|
}
|
|
for name, rule := range c.Broadcast {
|
|
args = append(args, "--broadcast="+name+"="+rule)
|
|
}
|
|
if c.Log {
|
|
args = append(args, "--log")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// NewConfig returns the address of a new [hst.BusConfig] with optional defaults.
|
|
func NewConfig(id string, defaults, mpris bool) *hst.BusConfig {
|
|
c := hst.BusConfig{
|
|
Call: make(map[string]string),
|
|
Broadcast: make(map[string]string),
|
|
|
|
Filter: true,
|
|
}
|
|
|
|
if defaults {
|
|
c.Talk = []string{"org.freedesktop.DBus", "org.freedesktop.Notifications"}
|
|
|
|
c.Call["org.freedesktop.portal.*"] = "*"
|
|
c.Broadcast["org.freedesktop.portal.*"] = "@/org/freedesktop/portal/*"
|
|
|
|
if id != "" {
|
|
c.Own = []string{id + ".*"}
|
|
if mpris {
|
|
c.Own = append(c.Own, "org.mpris.MediaPlayer2."+id+".*")
|
|
}
|
|
}
|
|
}
|
|
|
|
return &c
|
|
}
|