fix(windows): better logs for window title

This commit is contained in:
Jan De Dobbeleer 2022-04-05 07:53:57 +02:00 committed by Jan De Dobbeleer
parent ce8bfece2d
commit 923155e253
3 changed files with 12 additions and 6 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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{},