Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Note
This an experimental API that is shipped with our prerelease SDK. See WebView2 release notes.
interface ICoreWebView2ExperimentalEnvironment15
: public IUnknown
This is the ICoreWebView2Environment Experimental interface for detecting critical update.
Summary
| Members | Descriptions |
|---|---|
| add_RestartRequested | Adds an event handler for the RestartRequested event. |
| remove_RestartRequested | Removes an event handler previously added with add_RestartRequested. |
Applies to
| Product | Introduced |
|---|---|
| WebView2 Win32 | N/A |
| WebView2 Win32 Prerelease | 1.0.2895 |
Members
add_RestartRequested
Adds an event handler for the RestartRequested event.
public HRESULT add_RestartRequested(ICoreWebView2ExperimentalRestartRequestedEventHandler * eventHandler, EventRegistrationToken * token)
Add an event handler for the RestartRequested event. RestartRequested event is raised when there is a need to restart WebView2 process in order to apply certain beneficial updates.
RestartRequested gives developers the awareness of these necessary WebView2 restarts, allowing developers to resolve issues faster than waiting for end users to restart the app. Developer might want to give end users the ability to save their state before restarting. For apps with multiple processes that host WebView2s that share the same user data folder you need to make sure all WebView2 instances are closed and the associated WebView2 Runtime browser process exits. See BrowserProcessExited for more details.
// After the environment is successfully created,
// register a handler for
auto exp_env15 = m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment15>();
CHECK_FAILURE(exp_env15->add_RestartRequested(
Callback<ICoreWebView2ExperimentalRestartRequestedEventHandler>(
[this](
ICoreWebView2Environment* sender,
ICoreWebView2ExperimentalRestartRequestedEventArgs* args) -> HRESULT
{
COREWEBVIEW2_RESTART_REQUESTED_PRIORITY priority;
args->get_Priority(&priority);
if (priority == COREWEBVIEW2_RESTART_REQUESTED_PRIORITY_NORMAL)
{
// Remaind user to restart the app when they get a chance.
// Don't force user to restart.
MessageBox(
m_mainWindow, L"Please restart your app when you get a chance",
L"WebView Restart Requested", MB_OK);
}
else if (priority == COREWEBVIEW2_RESTART_REQUESTED_PRIORITY_HIGH)
{
// Don't block the event handler with a message box
RunAsync(
[this]()
{
std::wstring message = L"We detected there is a critical "
L"update for WebView2 runtime.";
if (m_webView)
{
message += L"Do you want to restart the app? \n\n";
message += L"Click No if you only want to re-create the "
L"webviews. \n";
message += L"Click Cancel for no action. \n";
}
int response = MessageBox(
m_mainWindow, message.c_str(), L"Critical Update Avaliable",
m_webView ? MB_YESNOCANCEL : MB_OK);
if (response == IDYES)
{
RestartApp();
}
else if (response == IDNO)
{
ReinitializeWebViewWithNewBrowser();
}
else
{
// do nothing
}
});
}
return S_OK;
})
.Get(),
nullptr));
remove_RestartRequested
Removes an event handler previously added with add_RestartRequested.
public HRESULT remove_RestartRequested(EventRegistrationToken token)