From 9966880bc8be412e20e85510f96d56e86b408bf2 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 24 Nov 2021 17:21:12 -0800 Subject: [PATCH] Only allow OnChange() to be called once --- pkg/player/player.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/player/player.go b/pkg/player/player.go index 5ed5e50..0d8e544 100644 --- a/pkg/player/player.go +++ b/pkg/player/player.go @@ -2,6 +2,7 @@ package player import ( "strings" + "sync" "github.com/godbus/dbus/v5" "go.arsenm.dev/infinitime/internal/utils" @@ -10,6 +11,7 @@ import ( var ( method, monitor *dbus.Conn monitorCh chan *dbus.Message + onChangeOnce sync.Once ) // Init makes required connections to DBis and @@ -130,7 +132,7 @@ func (ct ChangeType) String() string { // OnChange runs cb when a value changes func OnChange(cb func(ChangeType, string)) { - go func() { + go onChangeOnce.Do(func() { // For every message on channel for msg := range monitorCh { // Parse PropertiesChanged @@ -175,7 +177,7 @@ func OnChange(cb func(ChangeType, string)) { } } } - }() + }) } // getPlayerNames gets all DBus MPRIS player bus names