mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix(spotify): parse correctly when in WSL
This commit is contained in:
parent
33148ef8f9
commit
d05737a8e8
|
@ -3,7 +3,6 @@
|
||||||
package segments
|
package segments
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,17 +10,32 @@ func (s *Spotify) Enabled() bool {
|
||||||
if !s.env.IsWsl() {
|
if !s.env.IsWsl() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
tlist, err := s.env.RunCommand("tasklist.exe", "/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH")
|
tlist, err := s.env.RunCommand("tasklist.exe", "/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH")
|
||||||
if err != nil || strings.HasPrefix(tlist, "INFO") {
|
if err != nil || strings.HasPrefix(tlist, "INFO") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
records, err := csv.NewReader(strings.NewReader(tlist)).ReadAll()
|
|
||||||
if err != nil || len(records) == 0 {
|
records := strings.Split(tlist, "\n")
|
||||||
|
if len(records) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
title := record[len(record)-1]
|
fields := strings.Split(record, ",")
|
||||||
if strings.Contains(title, " - ") {
|
if len(fields) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// last elemant is the title
|
||||||
|
title := fields[len(fields)-1]
|
||||||
|
// trim leading and trailing quotes from the field
|
||||||
|
title = strings.TrimPrefix(title, `"`)
|
||||||
|
title = strings.TrimSuffix(title, `"`)
|
||||||
|
if !strings.Contains(title, " - ") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
infos := strings.Split(title, " - ")
|
infos := strings.Split(title, " - ")
|
||||||
s.Artist = infos[0]
|
s.Artist = infos[0]
|
||||||
s.Track = strings.Join(infos[1:], " - ")
|
s.Track = strings.Join(infos[1:], " - ")
|
||||||
|
@ -29,6 +43,6 @@ func (s *Spotify) Enabled() bool {
|
||||||
s.resolveIcon()
|
s.resolveIcon()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,17 @@ func TestSpotifyWsl(t *testing.T) {
|
||||||
"Spotify.exe","22052","Console","1","29,040 K","Unknown","PC\user","0:00:00","N/A"
|
"Spotify.exe","22052","Console","1","29,040 K","Unknown","PC\user","0:00:00","N/A"
|
||||||
"Spotify.exe","22072","Console","1","43,960 K","Unknown","PC\user","0:01:50","N/A"
|
"Spotify.exe","22072","Console","1","43,960 K","Unknown","PC\user","0:01:50","N/A"
|
||||||
"Spotify.exe","10404","Console","1","256,924 K","Unknown","PC\user","0:10:49","N/A"`,
|
"Spotify.exe","10404","Console","1","256,924 K","Unknown","PC\user","0:10:49","N/A"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "Spotify playing",
|
||||||
|
ExpectedString: "\ue602 Grabbitz - Another Form Of \"Goodbye\"",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
ExecOutput: `"Spotify.exe","13748","Console","1","303.744 K","Running","GARMIN\elderbroekowe","0:03:58","Grabbitz - Another Form Of "Goodbye""
|
||||||
|
"Spotify.exe","4208","Console","1","31.544 K","Running","GARMIN\elderbroekowe","0:00:00","N/A"
|
||||||
|
"Spotify.exe","14528","Console","1","184.020 K","Running","GARMIN\elderbroekowe","0:02:54","N/A"
|
||||||
|
"Spotify.exe","14488","Console","1","53.828 K","Unknown","GARMIN\elderbroekowe","0:00:08","N/A"
|
||||||
|
"Spotify.exe","14800","Console","1","29.576 K","Unknown","GARMIN\elderbroekowe","0:00:00","N/A"
|
||||||
|
"Spotify.exe","19836","Console","1","237.360 K","Unknown","GARMIN\elderbroekowe","0:07:46","N/A"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "tasklist.exe not in path",
|
Case: "tasklist.exe not in path",
|
||||||
|
|
Loading…
Reference in a new issue