Skip to content

Commit f85f34f

Browse files
authored
Update TryUpdateRuntime.md
1 parent a0e1a57 commit f85f34f

1 file changed

Lines changed: 42 additions & 41 deletions

File tree

specs/TryUpdateRuntime.md

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ async protected bool EnsureWebView2RuntimeVersion(string minimalVersionRequired)
2727
currentRuntimeVersion = CoreWebView2Environment.GetAvailableBrowserVersionString();
2828
return (CoreWebView2Environment.CompareBrowserVersions(currentRuntimeVersion, minimalVersionRequired) >= 0);
2929
}
30+
31+
// For the scenario where the app wants to light up features fast while running with the old version.
32+
{
33+
// Switch to new version by closing and recreating WebView.
34+
webView2Environment.NewBrowserVersionAvailable += delegate (object sender, object args)
35+
{
36+
// Close current WebView2 Control
37+
// Wait for it to completely shutdown
38+
// Recreate WebView2 Control to run with newer version
39+
};
40+
41+
// Trigger Edge WebView2 Runtime update, ignroe update result and rely on NewBrowserVersionAvailable to take action.
42+
EnsureWebView2RuntimeVersion(desiredVersion);
43+
}
44+
3045
```
3146
## Win32 C++
3247
```cpp
@@ -86,26 +101,7 @@ void EnsureWebView2RuntimeVersion(std::function<void(bool)> const& callback, std
86101
```
87102
88103
# Remarks
89-
Try to update installed Microsoft Edge WebView2 Runtime.
90-
This will potentially result in a new version of the Edge Webview2
91-
Runtime being installed and `NewBrowserVersionAvailable` event fired.
92-
There is no guarantee on the order of that event being fired and
93-
TryUpdateRuntimeis completed handler being invoked. Besides the
94-
`NewBrowserVersionAvailable` event, there will be no impact to any
95-
currently running WebViews when update is installed.
96-
The latest version can always be queried using `GetAvailableCoreWebView2BrowserVersionString` API.
97-
This is only supported for installed Edge WebView2 Runtime. When running
98-
fixed version Edge WebView2 Runtime or non stable channel Edge browser,
99-
this API will return `HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)`.
100-
There could only be one active TryUpdateRuntime operation, calling the API
101-
before completed handler for previous call is invoked will fail with
102-
`HRESULT_FROM_WIN32(ERROR_BUSY)`.
103-
Calling the API repeatedly in a short period of time, will also fail with
104-
`HRESULT_FROM_WIN32(ERROR_BUSY)`.
105-
The TryUpdateRuntime operation is associated with the CoreWebView2Environment
106-
object, on going TryUpdateRuntime operation will be aborted when the
107-
associated CoreWebView2Environment along with the CoreWebView2 objects that
108-
are created by the CoreWebView2Environment object are all released.
104+
See comments in [API Details](#api-details) section below.
109105
110106
# API Notes
111107
See [API Details](#api-details) section below for API reference.
@@ -114,30 +110,32 @@ See [API Details](#api-details) section below for API reference.
114110
115111
## Win32 C++
116112
```IDL
117-
/// Result of TryUpdateRuntime operation.
118-
[v1_enum] typedef enum COREWEBVIEW2_RUNTIME_UPDATE_STATUS {
113+
/// Status of TryUpdateRuntime operation result.
114+
[v1_enum] typedef enum COREWEBVIEW2_UPDATE_RUNTIME_STATUS {
119115
120116
/// No update for Edge WebView2 Runtime is available.
121-
COREWEBVIEW2_RUNTIME_UPDATE_STATUS_NO_UPDATE,
117+
/// Latest version of Edge WebView2 Runtime is already installed.
118+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS_NO_UPDATE,
122119
123120
/// Edge WebView2 Runtime is updated successfully.
124-
COREWEBVIEW2_RUNTIME_UPDATE_STATUS_UPDATED,
121+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS_UPDATED,
125122
126-
/// Edge WebView2 Runtime update is blocked by group policy. The caller
127-
/// should not retry.
128-
COREWEBVIEW2_RUNTIME_UPDATE_STATUS_BLOCKED_BY_POLICY,
123+
/// Edge WebView2 Runtime update is blocked by group policy.
124+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS_BLOCKED_BY_POLICY,
129125
130126
/// Edge WebView2 Runtime update failed.
131-
COREWEBVIEW2_RUNTIME_UPDATE_STATUS_FAILED,
132-
} COREWEBVIEW2_RUNTIME_UPDATE_STATUS;
127+
/// See `UpdateError` property of UpdateRuntimeResult for more
128+
/// information about the failure.
129+
COREWEBVIEW2_UPDATE_RUNTIME_STATUS_FAILED,
130+
} COREWEBVIEW2_UPDATE_RUNTIME_STATUS;
133131
134132
/// The TryUpdateRuntime result.
135133
[uuid(DD503E49-AB19-47C0-B2AD-6DDD09CC3E3A), object, pointer_default(unique)]
136134
interface ICoreWebView2ExperimentalUpdateRuntimeResult : IUnknown {
137135
138136
/// The status for the TryUpdateRuntime method.
139-
[propget] HRESULT UpdateRuntimeStatus(
140-
[ out, retval ] COREWEBVIEW2_RUNTIME_UPDATE_STATUS * updateResult);
137+
[propget] HRESULT Status(
138+
[ out, retval ] COREWEBVIEW2_UPDATE_RUNTIME_STATUS * status);
141139
142140
/// The update error happened while trying to update Edge WebView2 Runtime.
143141
[propget] HRESULT UpdateError([out, retval] HRESULT* updateError);
@@ -173,20 +171,23 @@ interface ICoreWebView2ExperimentalEnvironment3 : IUnknown {
173171
/// currently running WebViews when update is installed.
174172
/// The latest version can always be queried using
175173
/// `GetAvailableCoreWebView2BrowserVersionString` API.
176-
/// This is only supported for installed Edge WebView2 Runtime. When running
177-
/// fixed version Edge WebView2 Runtime or non stable channel Edge browser,
178-
/// this API will return `HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)`.
174+
/// The TryUpdateRuntime method is only supported for an installed Edge WebView2
175+
/// Runtime. When running a fixed version Edge WebView2 Runtime or non stable
176+
/// channel Edge browser, this API will return `HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)`.
179177
/// There could only be one active TryUpdateRuntime operation, calling the API
180178
/// before completed handler for previous call is invoked will fail with
181179
/// `HRESULT_FROM_WIN32(ERROR_BUSY)`.
182180
/// Calling the API repeatedly in a short period of time, will also fail with
183-
/// `HRESULT_FROM_WIN32(ERROR_BUSY)`.
181+
/// `HRESULT_FROM_WIN32(ERROR_BUSY)`. Don't call the API more than 3 times
182+
/// within 5 minutes.
184183
/// The TryUpdateRuntime operation is associated with the CoreWebView2Environment
185-
/// object, on going TryUpdateRuntime operation will be aborted when the
184+
/// object and any ongoing TryUpdateRuntime operation will be aborted when the
186185
/// associated CoreWebView2Environment along with the CoreWebView2 objects that
187-
/// are created by the CoreWebView2Environment object are all released.
186+
/// are created by the CoreWebView2Environment object are all released. In this
187+
/// case, the completed handler will be invoked with `S_OK` as `errorCode` and a
188+
/// result object with `Status` of COREWEBVIEW2_UPDATE_RUNTIME_STATUS_FAILED and
189+
/// `UpdateError` as `E_ABORT`.
188190
///
189-
/// \snippet AppWindow.cpp UpdateRuntime
190191
HRESULT TryUpdateRuntime(
191192
[in] ICoreWebView2ExperimentalTryUpdateRuntimeCompletedHandler *
192193
handler);
@@ -197,7 +198,7 @@ interface ICoreWebView2ExperimentalEnvironment3 : IUnknown {
197198
```c#
198199
namespace Microsoft.Web.WebView2.Core
199200
{
200-
public enum CoreWebView2RuntimeUpdateStatus
201+
public enum CoreWebView2UpdateRuntimeStatus
201202
{
202203
NoUpdate = 0,
203204
Updated = 1,
@@ -207,7 +208,7 @@ namespace Microsoft.Web.WebView2.Core
207208

208209
public partial class CoreWebView2UpdateRuntimeResult
209210
{
210-
public CoreWebView2RuntimeUpdateStatus UpdateRuntimeStatus
211+
public CoreWebView2UpdateRuntimeStatus Status
211212
{
212213
get;
213214
}
@@ -219,7 +220,7 @@ namespace Microsoft.Web.WebView2.Core
219220

220221
public partial class CoreWebView2Environment
221222
{
222-
public async Task<CoreWebView2UpdateRuntimeResult> TryUpdateRuntimeAsync();
223+
public async Task<CoreWebView2UpdateRuntimeResult> TryUpdateRuntimeAsync()
223224
}
224225
}
225226
```

0 commit comments

Comments
 (0)