Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Jan 14, 2024
1 parent 672e88a commit 5eae0e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/WinWebDiffLib/WebDiffWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CWebDiffWindow : public IWebDiffWindow
std::wstring userDataFolder = GetUserDataFolderPath(i);
ComPtr<IWebDiffCallback> callback2(callback);
hr = m_webWindow[i].Create(m_hInstance, m_hWnd, urls[i], userDataFolder.c_str(),
m_size, m_fitToWindow, m_zoom, m_userAgent, nullptr,
m_size, m_fitToWindow, m_zoom, m_userAgent, GetScriptOnLoad(), nullptr,
[this, i, callback2](WebDiffEvent::EVENT_TYPE event, IUnknown* sender, IUnknown* args)
{
WebDiffEvent ev{};
Expand Down Expand Up @@ -131,7 +131,6 @@ class CWebDiffWindow : public IWebDiffWindow
}
else if (event == WebDiffEvent::NavigationCompleted)
{
addEventListener(sender, ev.pane, nullptr);
m_documentLoaded[ev.pane] = true;
if ((std::count(m_documentLoaded, m_documentLoaded + m_nPanes, true) == m_nPanes) &&
(std::count(m_urlChanged, m_urlChanged + m_nPanes, true) == m_nPanes))
Expand All @@ -142,7 +141,6 @@ class CWebDiffWindow : public IWebDiffWindow
}
else if (event == WebDiffEvent::FrameNavigationCompleted)
{
addEventListener(sender,ev.pane, nullptr);
}
else if (event == WebDiffEvent::GoBacked)
{
Expand Down Expand Up @@ -854,11 +852,6 @@ class CWebDiffWindow : public IWebDiffWindow
return hr;
}

HRESULT addEventListener(IUnknown* sender, int pane, IWebDiffCallback* callback)
{
return m_webWindow[pane].ExecuteScript(sender, GetScriptOnLoad(), callback);
}

HRESULT syncEvent(int srcPane, const std::wstring& json)
{
for (int pane = 0; pane < m_nPanes; ++pane)
Expand Down
11 changes: 10 additions & 1 deletion src/WinWebDiffLib/WebWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class CWebWindow
settings2->put_UserAgent(userAgent.c_str());
}

m_webview->AddScriptToExecuteOnDocumentCreated(m_parent->GetScriptOnLoad(), nullptr);

m_webview->add_NewWindowRequested(
Callback<ICoreWebView2NewWindowRequestedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args) {
Expand Down Expand Up @@ -268,9 +270,10 @@ class CWebWindow
}

HRESULT Create(HINSTANCE hInstance, HWND hWndParent, const wchar_t* url, const wchar_t* userDataFolder,
const SIZE& size, bool fitToWindow, double zoom, std::wstring& userAgent,
const SIZE& size, bool fitToWindow, double zoom, std::wstring& userAgent, const wchar_t* scriptOnLoad,
IWebDiffCallback* callback, std::function<void(WebDiffEvent::EVENT_TYPE, IUnknown*, IUnknown*)> eventHandler)
{
m_scriptOnLoad = scriptOnLoad;
m_fitToWindow = fitToWindow;
m_size = size;
m_eventHandler = eventHandler;
Expand Down Expand Up @@ -423,6 +426,11 @@ class CWebWindow
return m_currentUrl.c_str();
}

const wchar_t* GetScriptOnLoad() const
{
return m_scriptOnLoad;
}

void CloseActiveTab()
{
if (!GetActiveWebView())
Expand Down Expand Up @@ -2084,6 +2092,7 @@ class CWebWindow
std::wstring m_toolTipText = L"test";
bool m_showToolTip = false;
std::wstring m_webmessage;
const wchar_t* m_scriptOnLoad;
inline static const auto GetDpiForWindowFunc = []() {
HMODULE hUser32 = GetModuleHandle(L"user32.dll");
return reinterpret_cast<decltype(&::GetDpiForWindow)>(
Expand Down

0 comments on commit 5eae0e1

Please sign in to comment.