@@ -613,7 +613,7 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
613613 CHECK_FEATURE_RETURN (experimentalEnvironment3);
614614 HRESULT hr = experimentalEnvironment3->UpdateRuntime (
615615 Callback<ICoreWebView2ExperimentalUpdateRuntimeCompletedHandler>(
616- [](HRESULT errorCode,
616+ [this ](HRESULT errorCode,
617617 ICoreWebView2ExperimentalUpdateRuntimeResult* result) -> HRESULT {
618618 HRESULT updateError = E_FAIL;
619619 COREWEBVIEW2_UPDATE_RUNTIME_STATUS status =
@@ -627,12 +627,12 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
627627 formattedMessage << " UpdateRuntime result (0x" << std::hex << errorCode
628628 << " ), status(" << status << " ), extendedError("
629629 << updateError << " )" ;
630- MessageBox ( nullptr , formattedMessage.str (). c_str ( ), nullptr , MB_OK );
630+ AsyncMessageBox ( std::move ( formattedMessage.str ()), L" UpdateRuntimeResult " );
631631 return S_OK;
632632 })
633633 .Get ());
634634 if (FAILED (hr))
635- ShowFailure (hr, L" Call to TryUpdateRuntime failed" );
635+ ShowFailure (hr, L" Call to UpdateRuntime failed" );
636636 // ! [UpdateRuntime]
637637 return true ;
638638 }
@@ -730,11 +730,8 @@ bool AppWindow::ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
730730 CHECK_FAILURE (webView2ExperimentalProfile4->ClearBrowsingDataInTimeRange (
731731 dataKinds, startTime, endTime,
732732 Callback<ICoreWebView2ExperimentalClearBrowsingDataCompletedHandler>(
733- [this ](HRESULT error)
734- -> HRESULT {
735- RunAsync ([this ]() {
736- MessageBox (nullptr , L" Completed" , L" Clear Browsing Data" , MB_OK);
737- });
733+ [this ](HRESULT error) -> HRESULT {
734+ AsyncMessageBox (L" Completed" , L" Clear Browsing Data" );
738735 return S_OK;
739736 })
740737 .Get ()));
@@ -877,7 +874,7 @@ void AppWindow::InitializeWebView()
877874 }
878875#endif
879876 // ! [CreateCoreWebView2EnvironmentWithOptions]
880- auto options = Microsoft::WRL::Make<CoreWebView2ExperimentalEnvironmentOptions >();
877+ auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions >();
881878 CHECK_FAILURE (
882879 options->put_AllowSingleSignOnUsingOSPrimaryAccount (
883880 m_AADSSOEnabled ? TRUE : FALSE ));
@@ -1153,6 +1150,11 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
11531150 CHECK_FAILURE (m_webView->Navigate (initialUri.c_str ()));
11541151 }
11551152 }
1153+ else if (result == E_ABORT)
1154+ {
1155+ // Webview creation was aborted because the user closed this window.
1156+ // No need to report this as an error.
1157+ }
11561158 else
11571159 {
11581160 ShowFailure (result, L" Failed to create webview" );
@@ -1349,29 +1351,33 @@ void AppWindow::RegisterEventHandlers()
13491351 CHECK_FAILURE (m_webViewEnvironment->add_NewBrowserVersionAvailable (
13501352 Callback<ICoreWebView2NewBrowserVersionAvailableEventHandler>(
13511353 [this ](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT {
1352- std::wstring message = L" We detected there is a new version for the browser. " ;
1353- if (m_webView)
1354+ // Don't block the event handler with a message box
1355+ RunAsync ([ this ]
13541356 {
1355- message += L" Do you want to restart the app? \n\n " ;
1356- message += L" Click No if you only want to re-create the webviews. \n " ;
1357- message += L" Click Cancel for no action. \n " ;
1358- }
1359- int response = MessageBox (
1360- m_mainWindow, message.c_str (), L" New available version" ,
1361- m_webView ? MB_YESNOCANCEL : MB_OK);
1357+ std::wstring message = L" We detected there is a new version for the browser." ;
1358+ if (m_webView)
1359+ {
1360+ message += L" Do you want to restart the app? \n\n " ;
1361+ message += L" Click No if you only want to re-create the webviews. \n " ;
1362+ message += L" Click Cancel for no action. \n " ;
1363+ }
1364+ int response = MessageBox (
1365+ m_mainWindow, message.c_str (), L" New available version" ,
1366+ m_webView ? MB_YESNOCANCEL : MB_OK);
13621367
1363- if (response == IDYES)
1364- {
1365- RestartApp ();
1366- }
1367- else if (response == IDNO)
1368- {
1369- ReinitializeWebViewWithNewBrowser ();
1370- }
1371- else
1372- {
1373- // do nothing
1374- }
1368+ if (response == IDYES)
1369+ {
1370+ RestartApp ();
1371+ }
1372+ else if (response == IDNO)
1373+ {
1374+ ReinitializeWebViewWithNewBrowser ();
1375+ }
1376+ else
1377+ {
1378+ // do nothing
1379+ }
1380+ });
13751381
13761382 return S_OK;
13771383 })
@@ -1466,12 +1472,9 @@ bool AppWindow::CloseWebView(bool cleanupUserDataFolder)
14661472 // The exiting process is not the last in use. Do not attempt cleanup
14671473 // as we might still have a webview open over the user data folder.
14681474 // Do not block from event handler.
1469- RunAsync ([this ]() {
1470- MessageBox (
1471- m_mainWindow,
1472- L" A new browser process prevented cleanup of the user data folder." ,
1473- L" Cleanup User Data Folder" , MB_OK);
1474- });
1475+ AsyncMessageBox (
1476+ L" A new browser process prevented cleanup of the user data folder." ,
1477+ L" Cleanup User Data Folder" );
14751478 }
14761479
14771480 return S_OK;
@@ -1692,6 +1695,14 @@ void AppWindow::RunAsync(std::function<void()> callback)
16921695 PostMessage (m_mainWindow, s_runAsyncWindowMessage, reinterpret_cast <WPARAM>(task), 0 );
16931696}
16941697
1698+ void AppWindow::AsyncMessageBox (std::wstring message, std::wstring title)
1699+ {
1700+ RunAsync ([this , message = std::move (message), title = std::move (title)]
1701+ {
1702+ MessageBox (m_mainWindow, message.c_str (), title.c_str (), MB_OK);
1703+ });
1704+ }
1705+
16951706void AppWindow::EnterFullScreen ()
16961707{
16971708 DWORD style = GetWindowLong (m_mainWindow, GWL_STYLE);
0 commit comments