Patch wxWidget CMake to download and use recent WebView2 library

This commit is contained in:
Jan Bařtipán 2024-07-02 17:02:01 +02:00 committed by Lukas Matena
parent 6a78caa6a7
commit fc76ec00f1
3 changed files with 25 additions and 28 deletions

15
deps/+wxWidgets/webview.patch vendored Normal file
View File

@ -0,0 +1,15 @@
diff -ur build.orig/cmake/lib/webview/CMakeLists.txt build/cmake/lib/webview/CMakeLists.txt
--- wxWidgets.orig/build/cmake/lib/webview/CMakeLists.txt 2024-06-14 19:02:36.000000000 +0200
+++ wxWidgets/build/cmake/lib/webview/CMakeLists.txt 2024-07-01 16:21:52.922737200 +0200
@@ -46,9 +46,9 @@
elseif(WXMSW)
if(wxUSE_WEBVIEW_EDGE)
# Update the following variables if updating WebView2 SDK
- set(WEBVIEW2_VERSION "1.0.705.50")
+ set(WEBVIEW2_VERSION "1.0.2592.51")
set(WEBVIEW2_URL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/${WEBVIEW2_VERSION}")
- set(WEBVIEW2_SHA256 "6a34bb553e18cfac7297b4031f3eac2558e439f8d16a45945c22945ac404105d")
+ set(WEBVIEW2_SHA256 "805c79e05184fab18c9fe7b8ba820c598399b97adc1fbf5b0ea490efad91d5b8")
set(WEBVIEW2_DEFAULT_PACKAGE_DIR "${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2.${WEBVIEW2_VERSION}")

View File

@ -30,6 +30,7 @@ endif ()
add_cmake_project(wxWidgets
URL https://github.com/prusa3d/wxWidgets/archive/323a465e577e03f330e2e6a4c78e564d125340cb.zip
URL_HASH SHA256=B538E4AD3CC93117932F4DED70C476D6650F9C70A9D4055A08F3693864C47465
PATCH_COMMAND COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/webview.patch
CMAKE_ARGS
"-DCMAKE_DEBUG_POSTFIX:STRING="
-DwxBUILD_PRECOMP=ON

View File

@ -4,6 +4,7 @@
#include "WebView2.h"
#include <wrl.h>
#include <atlbase.h>
#include <boost/log/trivial.hpp>
#include "wx/msw/private/comptr.h"
@ -15,59 +16,39 @@ namespace Slic3r::GUI {
void setup_webview_with_credentials(wxWebView* webview, const std::string& username, const std::string& password)
{
ICoreWebView2 *webView2 = (ICoreWebView2 *) webview->GetNativeBackend();
ICoreWebView2 *webView2 = static_cast<ICoreWebView2 *>(webview->GetNativeBackend());
wxCOMPtr<ICoreWebView2_2> webview2Com;
wxCOMPtr<ICoreWebView2Environment> environment;
if(FAILED(webView2->QueryInterface(IID_PPV_ARGS(&webview2Com))))
{
return;
}
if (FAILED(webview2Com->get_Environment(&environment))) {
return;
}
LPWSTR wideString;
if (SUCCEEDED(environment->get_BrowserVersionString(&wideString))) {
std::wcout << L"WebView2 runtime version: " << wideString << std::endl;
}
wxCOMPtr<ICoreWebView2_10> wv2_10;
//if (!SUCCEEDED(webView2->QueryInterface(IID_PPV_ARGS(&wv2_10)))) {
//wv2_10 = wil::com_ptr<ICoreWebView2>(m_appWindow->GetWebView()).query<ICoreWebView2_2>();
// auto webView10 = webView2->query<ICoreWebView2_10>()
HRESULT hr = webView2->QueryInterface(IID_PPV_ARGS(&wv2_10));
if (FAILED(hr)) {
return;
}
// should it be stored?
EventRegistrationToken basicAuthenticationRequestedToken = {};
if (!SUCCEEDED(wv2_10->add_BasicAuthenticationRequested(
if (FAILED(wv2_10->add_BasicAuthenticationRequested(
Microsoft::WRL::Callback<ICoreWebView2BasicAuthenticationRequestedEventHandler>(
[username, password](ICoreWebView2 *sender, ICoreWebView2BasicAuthenticationRequestedEventArgs *args) {
wxCOMPtr<ICoreWebView2BasicAuthenticationResponse> basicAuthenticationResponse;
if (!SUCCEEDED(args->get_Response(&basicAuthenticationResponse))) {
if (FAILED(args->get_Response(&basicAuthenticationResponse))) {
return -1;
}
if (!SUCCEEDED(basicAuthenticationResponse->put_UserName(GUI::from_u8(username).c_str()))) {
if (FAILED(basicAuthenticationResponse->put_UserName(GUI::from_u8(username).c_str()))) {
return -1;
}
if (!SUCCEEDED(basicAuthenticationResponse->put_Password(GUI::from_u8(password).c_str()))) {
if (FAILED(basicAuthenticationResponse->put_Password(GUI::from_u8(password).c_str()))) {
return -1;
}
return 0;
}
).Get(),
&basicAuthenticationRequestedToken
)))
{
))) {
BOOST_LOG_TRIVIAL(error) << "WebView: Cannot register authentication request handler";
}
wv2_10->Release();
}
#endif