aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarvey Tindall <hrfee@protonmail.ch>2020-08-27 20:26:01 +0100
committerHarvey Tindall <hrfee@protonmail.ch>2020-08-27 20:26:01 +0100
commit315b3df656ec2bb38f3b6f326aea8d312775af3b (patch)
treeba055e788b3da4ffab387a735dd1f81afe0d57c4
parentf9b38e5d1ddb10dc0316ac35b097adfe1da59d8d (diff)
downloadwaybar-mpris-315b3df656ec2bb38f3b6f326aea8d312775af3b.tar.gz
waybar-mpris-315b3df656ec2bb38f3b6f326aea8d312775af3b.zip
add list command for debug
responds with the current list of players and some info, to be used for debugging purposes
-rw-r--r--main.go35
-rwxr-xr-xwaybar-mprisbin952016 -> 953096 bytes
2 files changed, 32 insertions, 3 deletions
diff --git a/main.go b/main.go
index 073366d..97064c0 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"net"
"os"
"sort"
+ "strconv"
"strings"
"time"
@@ -29,6 +30,7 @@ var knownBrowsers = map[string]string{
type Player struct {
player dbus.BusObject
fullName, name, title, artist, album string
+ pid uint32
playing, stopped bool
metadata map[string]dbus.Variant
conn *dbus.Conn
@@ -50,19 +52,19 @@ var (
SEP = " - "
ORDER = "SYMBOL:ARTIST:ALBUM:TITLE:POSITION"
AUTOFOCUS = false
- COMMANDS = []string{"player-next", "player-prev", "next", "prev", "toggle"}
+ COMMANDS = []string{"player-next", "player-prev", "next", "prev", "toggle", "list"}
SHOW_POS = false
)
// NewPlayer returns a new player object.
func NewPlayer(conn *dbus.Conn, name string) (p *Player) {
playerName := strings.ReplaceAll(name, INTERFACE+".", "")
+ var pid uint32
+ conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, name).Store(&pid)
for key, val := range knownPlayers {
if strings.Contains(name, key) {
playerName = val
if val == "Browser" {
- var pid uint32
- conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, name).Store(&pid)
file, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
if err == nil {
cmd := string(file)
@@ -82,6 +84,7 @@ func NewPlayer(conn *dbus.Conn, name string) (p *Player) {
conn: conn,
name: playerName,
fullName: name,
+ pid: pid,
}
p.Refresh()
return
@@ -369,6 +372,16 @@ func main() {
log.Fatalln("Couldn't send command")
}
fmt.Println("Sent.")
+ if command == "list" {
+ buf := make([]byte, 512)
+ nr, err := conn.Read(buf)
+ if err != nil {
+ log.Fatalf("Couldn't read response.")
+ }
+ response := string(buf[0:nr])
+ fmt.Println("Response:")
+ fmt.Printf(response)
+ }
} else {
conn, err := dbus.SessionBus()
if err != nil {
@@ -426,6 +439,22 @@ func main() {
players.Prev()
} else if command == "toggle" {
players.Toggle()
+ } else if command == "list" {
+ resp := ""
+ pad := 0
+ i := len(players.list)
+ for i != 0 {
+ i /= 10
+ pad++
+ }
+ for i, p := range players.list {
+ symbol := ""
+ if uint(i) == players.current {
+ symbol = "*"
+ }
+ resp += fmt.Sprintf("%0"+strconv.Itoa(pad)+"d%s: Name: %s; Playing: %t; PID: %d\n", i, symbol, p.fullName, p.playing, p.pid)
+ }
+ con.Write([]byte(resp))
} else {
fmt.Println("Invalid command")
}
diff --git a/waybar-mpris b/waybar-mpris
index 09e062e..50df87b 100755
--- a/waybar-mpris
+++ b/waybar-mpris
Binary files differ