Skip to content

Commit 421277f

Browse files
author
Ognjen Sobajic
committed
Update the sample apps.
Win32 works with 1.0.818.41-prerelease WPF and WinForms work with 1.0.818.41
1 parent 9d01c46 commit 421277f

File tree

11 files changed

+1520
-126
lines changed

11 files changed

+1520
-126
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <regex>
1212
#include <string>
1313
#include <vector>
14+
#include <iostream>
15+
#include <sstream>
1416
#include <ShObjIdl_core.h>
1517
#include <Shellapi.h>
1618
#include <ShlObj_core.h>
@@ -475,6 +477,44 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
475477
MB_OK);
476478
return true;
477479
}
480+
case IDM_UPDATE_RUNTIME:
481+
{
482+
if (!m_webViewEnvironment)
483+
{
484+
MessageBox(
485+
m_mainWindow, L"Need WebView2 environment object to update WebView2 Runtime",
486+
nullptr, MB_OK);
487+
return true;
488+
}
489+
//! [UpdateRuntime]
490+
auto experimentalEnvironment3 =
491+
m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment3>();
492+
CHECK_FEATURE_RETURN(experimentalEnvironment3);
493+
HRESULT hr = experimentalEnvironment3->UpdateRuntime(
494+
Callback<ICoreWebView2ExperimentalUpdateRuntimeCompletedHandler>(
495+
[](HRESULT errorCode,
496+
ICoreWebView2ExperimentalUpdateRuntimeResult* result) -> HRESULT {
497+
HRESULT updateError = E_FAIL;
498+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS status =
499+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS_FAILED;
500+
if ((errorCode == S_OK) && result)
501+
{
502+
CHECK_FAILURE(result->get_Status(&status));
503+
CHECK_FAILURE(result->get_ExtendedError(&updateError));
504+
}
505+
std::wstringstream formattedMessage;
506+
formattedMessage << "UpdateRuntime result (0x" << std::hex << errorCode
507+
<< "), status(" << status << "), extendedError("
508+
<< updateError << ")";
509+
MessageBox(nullptr, formattedMessage.str().c_str(), nullptr, MB_OK);
510+
return S_OK;
511+
})
512+
.Get());
513+
if (FAILED(hr))
514+
ShowFailure(hr, L"Call to TryUpdateRuntime failed");
515+
//! [UpdateRuntime]
516+
return true;
517+
}
478518
case IDM_EXIT:
479519
CloseAppWindow();
480520
return true;
@@ -790,6 +830,11 @@ void AppWindow::ReinitializeWebView()
790830

791831
void AppWindow::ReinitializeWebViewWithNewBrowser()
792832
{
833+
if (!m_webView)
834+
{
835+
ReinitializeWebView();
836+
return;
837+
}
793838
// Save the settings component from being deleted when the WebView is closed, so we can
794839
// copy its properties to the next settings component.
795840
m_oldSettingsComponent = MoveComponent<SettingsComponent>();

0 commit comments

Comments
 (0)