···1212 Runs cover-viewer in visualizer or notify. In visualizer mode it displays the
1313 album cover of the file read from the socket. In notify, reads cmus status line
1414 from stdin and sends the file path to the socket.
1515- --socket
1616- Allows to change the location of the UNIX socket used to send and read the cmus
1717- status line.
1815*/
1916package main
2017···5350 log.SetFlags(log.LstdFlags | log.Lshortfile)
54515552 mode := flag.String("mode", "", "visualizer or notify")
5656- socketPath := flag.String("socket", "/tmp/music-viewer.sock", "unix socket path")
5753 flag.Parse()
5454+5555+ socketPath := getSocketPath()
58565957 switch *mode {
6058 case "visualizer":
6161- if err := runVisualizer(*socketPath); err != nil {
5959+ if err := runVisualizer(socketPath); err != nil {
6260 fmt.Fprintln(os.Stderr, "visualize error:", err)
6361 os.Exit(1)
6462 }
6563 case "notify":
6666- if err := runNotify(*socketPath); err != nil {
6464+ if err := runNotify(socketPath); err != nil {
6765 fmt.Fprintln(os.Stderr, "notify error:", err)
6866 os.Exit(1)
6967 }
···7169 fmt.Fprintln(os.Stderr, "usage: --mode visualizer|notify")
7270 os.Exit(1)
7371 }
7272+}
7373+7474+// getSocketPath gets the socket path
7575+func getSocketPath() string {
7676+ if xdg := os.Getenv("XDG_RUNTIME_DIR"); xdg != "" {
7777+ return xdg + "/music-viewer.sock"
7878+ }
7979+ return "/tmp/music-viewer.sock"
7480}
75817682// runNotify writes in the socket the content of the Stdin, meant to be the status