display browser name in tooltip
reads /proc/<pid>/cmdline directly instead of using a library.
This commit is contained in:
		
							parent
							
								
									840130680e
								
							
						
					
					
						commit
						623adf487e
					
				@ -15,7 +15,7 @@ MPRIS2 is widely supported, so this component should work with:
 | 
				
			|||||||
* Most other music/media players
 | 
					* Most other music/media players
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Install
 | 
					## Install
 | 
				
			||||||
`go get github.com/hrfee/waybar-mpris`
 | 
					`go get github.com/hrfee/waybar-mpris` will install the program, as well as the go dbus bindings and pflags for command-line arguments.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
or just grab the `waybar-mpris` binary from here and place it in your PATH.
 | 
					or just grab the `waybar-mpris` binary from here and place it in your PATH.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								main.go
									
									
									
									
									
								
							@ -5,6 +5,7 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/godbus/dbus/v5"
 | 
						"github.com/godbus/dbus/v5"
 | 
				
			||||||
	flag "github.com/spf13/pflag"
 | 
						flag "github.com/spf13/pflag"
 | 
				
			||||||
 | 
						"io/ioutil"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@ -17,6 +18,12 @@ var knownPlayers = map[string]string{
 | 
				
			|||||||
	"noson":                      "Noson",
 | 
						"noson":                      "Noson",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var knownBrowsers = map[string]string{
 | 
				
			||||||
 | 
						"mozilla":  "Firefox",
 | 
				
			||||||
 | 
						"chrome":   "Chrome",
 | 
				
			||||||
 | 
						"chromium": "Chromium",
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Player struct {
 | 
					type Player struct {
 | 
				
			||||||
	player                               dbus.BusObject
 | 
						player                               dbus.BusObject
 | 
				
			||||||
	fullName, name, title, artist, album string
 | 
						fullName, name, title, artist, album string
 | 
				
			||||||
@ -50,6 +57,20 @@ func NewPlayer(conn *dbus.Conn, name string) (p *Player) {
 | 
				
			|||||||
	for key, val := range knownPlayers {
 | 
						for key, val := range knownPlayers {
 | 
				
			||||||
		if strings.Contains(name, key) {
 | 
							if strings.Contains(name, key) {
 | 
				
			||||||
			playerName = val
 | 
								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)
 | 
				
			||||||
 | 
										for k, v := range knownBrowsers {
 | 
				
			||||||
 | 
											if strings.Contains(cmd, k) {
 | 
				
			||||||
 | 
												playerName = v
 | 
				
			||||||
 | 
												break
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								waybar-mpris
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								waybar-mpris
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user