fix(spotify): ignore errors

resolves #2031
This commit is contained in:
Jan De Dobbeleer 2022-04-05 21:15:48 +02:00 committed by Jan De Dobbeleer
parent 46992bc7e0
commit be06c89627

View file

@ -57,21 +57,14 @@ func getWindowText(hwnd syscall.Handle, str *uint16, maxCount int32) (length int
func getWindowFileName(handle syscall.Handle) (string, error) {
var pid int
// get pid
_, _, err := procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))
if err != nil && err.Error() != "The operation completed successfully." {
return "", errors.New("unable to get window process pid")
}
_, _, _ = procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))
const query = windows.PROCESS_QUERY_INFORMATION | windows.PROCESS_VM_READ
h, err := windows.OpenProcess(query, false, uint32(pid))
if err != nil {
return "", errors.New("unable to open window process")
}
buf := [1024]byte{}
length, _, err := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)
if err != nil && err.Error() != "The operation completed successfully." {
return "", errors.New("unable to get window process name")
}
length, _, _ := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)
filename := string(buf[:length])
return strings.ToLower(filename), nil
}