An application to display the albumn cover of the track played in cmus.

feat: use XDG_RUNTIME_DIR to place the unix socket

+12 -6
+12 -6
main.go
··· 12 12 Runs cover-viewer in visualizer or notify. In visualizer mode it displays the 13 13 album cover of the file read from the socket. In notify, reads cmus status line 14 14 from stdin and sends the file path to the socket. 15 - --socket 16 - Allows to change the location of the UNIX socket used to send and read the cmus 17 - status line. 18 15 */ 19 16 package main 20 17 ··· 53 50 log.SetFlags(log.LstdFlags | log.Lshortfile) 54 51 55 52 mode := flag.String("mode", "", "visualizer or notify") 56 - socketPath := flag.String("socket", "/tmp/music-viewer.sock", "unix socket path") 57 53 flag.Parse() 54 + 55 + socketPath := getSocketPath() 58 56 59 57 switch *mode { 60 58 case "visualizer": 61 - if err := runVisualizer(*socketPath); err != nil { 59 + if err := runVisualizer(socketPath); err != nil { 62 60 fmt.Fprintln(os.Stderr, "visualize error:", err) 63 61 os.Exit(1) 64 62 } 65 63 case "notify": 66 - if err := runNotify(*socketPath); err != nil { 64 + if err := runNotify(socketPath); err != nil { 67 65 fmt.Fprintln(os.Stderr, "notify error:", err) 68 66 os.Exit(1) 69 67 } ··· 71 69 fmt.Fprintln(os.Stderr, "usage: --mode visualizer|notify") 72 70 os.Exit(1) 73 71 } 72 + } 73 + 74 + // getSocketPath gets the socket path 75 + func getSocketPath() string { 76 + if xdg := os.Getenv("XDG_RUNTIME_DIR"); xdg != "" { 77 + return xdg + "/music-viewer.sock" 78 + } 79 + return "/tmp/music-viewer.sock" 74 80 } 75 81 76 82 // runNotify writes in the socket the content of the Stdin, meant to be the status