mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
fix(windows): better logs for window title
This commit is contained in:
parent
ce8bfece2d
commit
923155e253
|
@ -108,9 +108,9 @@ func queryWindowTitles(processName, windowTitleRegex string) (string, error) {
|
|||
// The error is not checked because if EnumWindows is stopped bofere enumerating all windows
|
||||
// it returns 0(error occurred) instead of 1(success)
|
||||
// In our case, title will equal "" or the title of the window anyway
|
||||
_ = enumWindows(cb, 0)
|
||||
err := enumWindows(cb, 0)
|
||||
if len(title) == 0 {
|
||||
return "", errors.New("no matching window title found")
|
||||
return "", errors.New("no matching window title found\n" + err.Error())
|
||||
}
|
||||
return title, nil
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
func (s *Spotify) Enabled() bool {
|
||||
// search for spotify window to retrieve the title
|
||||
// Can be either "Spotify xxx" or the song name "Candlemass - Spellbreaker"
|
||||
windowTitle, err := s.env.QueryWindowTitles("spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$")
|
||||
windowTitle, err := s.env.QueryWindowTitles("spotify.exe", `^(Spotify.*)|(.*\s-\s.*)$`)
|
||||
if err == nil {
|
||||
return s.parseSpotifyTitle(windowTitle, " - ")
|
||||
}
|
||||
windowTitle, err = s.env.QueryWindowTitles("msedge.exe", "^(Spotify.*)")
|
||||
windowTitle, err = s.env.QueryWindowTitles("msedge.exe", `^(Spotify.*)`)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -30,11 +30,17 @@ func TestSpotifyWindowsNative(t *testing.T) {
|
|||
ExpectedEnabled: false,
|
||||
Title: "Spotify premium",
|
||||
},
|
||||
{
|
||||
Case: "Playing - new",
|
||||
ExpectedString: "\ue602 Demon Hunter - Collapsing (feat. Björn \"Speed\" Strid)",
|
||||
ExpectedEnabled: true,
|
||||
Title: `Demon Hunter - Collapsing (feat. Björn "Speed" Strid)`,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.On("QueryWindowTitles", "spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$").Return(tc.Title, tc.Error)
|
||||
env.On("QueryWindowTitles", "msedge.exe", "^(Spotify.*)").Return("", errors.New("not implemented"))
|
||||
env.On("QueryWindowTitles", "spotify.exe", `^(Spotify.*)|(.*\s-\s.*)$`).Return(tc.Title, tc.Error)
|
||||
env.On("QueryWindowTitles", "msedge.exe", `^(Spotify.*)`).Return("", errors.New("not implemented"))
|
||||
s := &Spotify{
|
||||
env: env,
|
||||
props: properties.Map{},
|
||||
|
|
Loading…
Reference in a new issue