From 01250ffd747ee1b0480ac5c8241af8fc78d757bf Mon Sep 17 00:00:00 2001
From: Francesco Minnocci <ad17fmin@uwcad.it>
Date: Fri, 12 Jan 2024 01:51:49 +0100
Subject: [PATCH] fix: remove pattern matching in favor of checking both for
 bus name with and without the instance

---
 services/mpris/mpris_unix.go | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/services/mpris/mpris_unix.go b/services/mpris/mpris_unix.go
index 7e0b865..d8622c1 100644
--- a/services/mpris/mpris_unix.go
+++ b/services/mpris/mpris_unix.go
@@ -3,7 +3,6 @@
 package mpris
 
 import (
-	"path"
 	"sptlrx/player"
 	"strings"
 
@@ -38,15 +37,13 @@ func (c *Client) getPlayer() (*mpris.Player, error) {
 		return mpris.New(conn, players[0]), nil
 	}
 
-	// iterating over configured names
+	// iterating over configured whitelisted players
 	for _, p := range c.players {
+		// adding the D-Bus bus name prefix
+		p := "org.mpris.MediaPlayer2." + p
 		for _, player := range players {
-			// support pattern matching
-			match, err := path.Match("org.mpris.MediaPlayer2."+p, player)
-			if err != nil {
-				return nil, err
-			}
-			if match {
+			// check for the name with and without the instance suffix
+			if p == player || strings.HasPrefix(player, p+".instance") {
 				return mpris.New(conn, player), nil
 			}
 		}