mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 22:07:25 -08:00
b8d3f5781c
If we are in a WSL environment and tasklist.exe is in our PATH, leverage it to scan for the Spotify.exe window title. Add unit tests and a new mock for env.isWSL
34 lines
737 B
Go
34 lines
737 B
Go
//go:build !darwin && !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"strings"
|
|
)
|
|
|
|
func (s *spotify) enabled() bool {
|
|
if !s.env.isWsl() {
|
|
return false
|
|
}
|
|
tlist, err := s.env.runCommand("tasklist.exe", "/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH")
|
|
if err != nil || strings.HasPrefix(tlist, "INFO") {
|
|
return false
|
|
}
|
|
records, err := csv.NewReader(strings.NewReader(tlist)).ReadAll()
|
|
if err != nil || len(records) == 0 {
|
|
return false
|
|
}
|
|
for _, record := range records {
|
|
title := record[len(record)-1]
|
|
if strings.Contains(title, " - ") {
|
|
infos := strings.Split(title, " - ")
|
|
s.artist = infos[0]
|
|
s.track = strings.Join(infos[1:], " - ")
|
|
s.status = "playing"
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|