From 3a1a9262b044bf84e72985e01933019c75487252 Mon Sep 17 00:00:00 2001 From: defektive Date: Wed, 10 Nov 2021 19:47:26 +0000 Subject: [PATCH] dont connect to pulse unless we have a volume module in use --- lib/pulse/pulse.go | 16 ++++++++++------ ui/module/volume.go | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/pulse/pulse.go b/lib/pulse/pulse.go index e67f797..8152550 100644 --- a/lib/pulse/pulse.go +++ b/lib/pulse/pulse.go @@ -12,18 +12,22 @@ import ( log "github.com/sirupsen/logrus" ) +var initialized = false var currentVolume float64 var lock sync.Mutex var watchers []chan struct{} -func init() { - log.Info("connecting to pulse") - r := C.initialize() - if r != 0 { - log.Error("could not connect to pulse") +func Init() { + if !initialized { + initialized = true + log.Info("connecting to pulse") + r := C.initialize() + if r != 0 { + log.Error("could not connect to pulse") + } + go C.run() } - go C.run() } func Volume() float64 { diff --git a/ui/module/volume.go b/ui/module/volume.go index 0625ff7..83524ba 100644 --- a/ui/module/volume.go +++ b/ui/module/volume.go @@ -30,6 +30,7 @@ func NewVolume(p ui.ParentDrawable, mk *markup.Markup) *Volume { } func (m *Volume) Init() error { + pulse.Init() _, err := m.mk.Parse(m, m, `