Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Adding logic to log all urls when no match is found
Browse files Browse the repository at this point in the history
  • Loading branch information
andysterland committed May 26, 2016
1 parent fe89156 commit aecbc4b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
57 changes: 37 additions & 20 deletions src/MicrosoftEdgeLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ HRESULT LaunchEdge(_In_ PCWSTR pszUrl, _In_ BOOL bKeepAlive)
return E_NOINTERFACE;
}

info.pDoc->put_URL(SysAllocString(pszUrl));
if (info.pDoc == nullptr)
{
return E_NOINTERFACE;
}

CComPtr<IHTMLWindow2> spWindow;
hr = info.pDoc->get_parentWindow(&spWindow);
if (!SUCCEEDED(hr))
{
ShowLastError(L"Failed to get the IHTMLWindow2");
return hr;
}

spWindow->navigate(SysAllocString(pszUrl));
if (!SUCCEEDED(hr))
{
ShowLastError(L"Failed to navigate to launch URL");
return hr;
}

hr = WaitForProcessToExit(info.pid);
return hr;
Expand Down Expand Up @@ -184,7 +202,8 @@ EdgeTargetInfo WatchForEdgeTab(_In_ PCWSTR pszUrl)
{
EdgeTargetInfo info = { 0 };
int loopCounter = 0;
int waitTimeMS = 2000;
int waitTimeMS = 1000;
int maxTries = 20;

do
{
Expand All @@ -202,8 +221,17 @@ EdgeTargetInfo WatchForEdgeTab(_In_ PCWSTR pszUrl)
}
}

if (loopCounter > 5)
if (loopCounter > maxTries)
{
std::cout << "\nCouldn't find Edge URL with URL: " << pszUrl;
std::cout << "\nFound";

for (size_t i = 0; i < vTargets.size(); i++)
{
EdgeTargetInfo info = vTargets[i];
std::cout << "\n" << info.url;
}

return{ 0 };
}
} while (info.pid == 0);
Expand Down Expand Up @@ -242,27 +270,16 @@ HRESULT EnumerateTargets(vector<EdgeTargetInfo>& vTargets)
HRESULT hr = Helpers::GetDocumentFromHwnd(hwnd, spDocument);
if (hr == S_OK)
{
CComBSTR url;
hr = spDocument->get_URL(&url);
if (hr != S_OK)
{
url = L"unknown";
}
EdgeTargetInfo i;
i.hwnd = hwnd;
i.pid = processId;
i.pDoc = spDocument;

CComBSTR title;
hr = spDocument->get_title(&title);
hr = spDocument->get_URL(&i.url);
if (hr != S_OK)
{
title = L"";
i.url = L"unknown";
}

EdgeTargetInfo i;
i.hwnd = hwnd;
i.url = url;
i.title = title;
i.processName = processName;
i.pid = processId;
i.pDoc = spDocument;
vTargets.push_back(i);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/MicrosoftEdgeLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
struct EdgeTargetInfo
{
HWND hwnd;
PCWSTR title;
PCWSTR url;
PCWSTR processName;
BSTR url;
DWORD pid;
IHTMLDocument2 *pDoc;
};
Expand Down

0 comments on commit aecbc4b

Please sign in to comment.