Skip to content

Commit

Permalink
fix bug when closing TIDAL app & improve update accuracy
Browse files Browse the repository at this point in the history
Signed-off-by: Stavros Avramidis <[email protected]>
  • Loading branch information
purpl3F0x committed Oct 13, 2019
1 parent 1f33639 commit 9f9e46a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ inline void rpcLoop() {
updateDiscordPresence(curSong);
} else {
Discord_ClearPresence();
curSong = Song();
}
_continue:

Expand Down
24 changes: 17 additions & 7 deletions windows_api_hook.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ inline std::string rawWstringToString(const std::wstring &wstr) {
/// @brief Enum describing the state of TIDAL app
enum status { error, closed, opened, playing };


/**
* @brief struct to be passed to <enumWindowsProc>
*/
struct EnumWindowsProcParam {
std::vector<DWORD> &pids;
std::wstring &song;
std::wstring &artist;
status tidalStatus = closed;
std::vector<DWORD> &pids;
std::wstring &song;
std::wstring &artist;
status tidalStatus = closed;


EnumWindowsProcParam(std::vector<DWORD> &pids, std::wstring &song, std::wstring &artist)
: pids(pids), song(song), artist(artist) {}
EnumWindowsProcParam(std::vector<DWORD> &pids, std::wstring &song, std::wstring &artist)
: pids(pids), song(song), artist(artist) {}
};


Expand All @@ -67,11 +68,20 @@ BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {

for (DWORD pid : (paramRe.pids)) {
if (winId == pid) {
paramRe.tidalStatus = opened;

std::wstring title(GetWindowTextLength(hwnd) + 1, L'\0');
GetWindowTextW(hwnd, &title[0], title.size()); //note: >=C++11

if (title.find(L"MSCTFIME UI") == 0
|| title.find(L"Default IME") == 0
|| title.find(L"MediaPlayer SMTC window") == 0
|| title.size() == 1
) {
return TRUE;
}
std::wcout << title << "\n";
paramRe.tidalStatus = opened;

std::regex_match(title, rgx);
std::wsmatch matches;

Expand Down

0 comments on commit 9f9e46a

Please sign in to comment.