Skip to content

Commit 1075af5

Browse files
committed
Change preferUnstableChannel implementation
Instead of specifying an environment variable, set ChannelSearchKind on CoreWebView2EnvironmentOptions.
1 parent 6dcb1cb commit 1075af5

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/WebView.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <string>
55
#include <wrl.h>
66
#include <wil/com.h>
7+
78
#include "WebView2.h"
9+
#include "WebView2EnvironmentOptions.h"
810

911
#include "Utils.h"
1012
#include "Config.h"
@@ -35,14 +37,6 @@ int CALLBACK WinMain(
3537
std::string configJsonPath = FolderFromPath(GetModulePath()) + "config.json";
3638
ConfigJson configJson = LoadConfigJson(configJsonPath);
3739

38-
// The default channel search order is the WebView2 Runtime, Beta, Dev, and Canary (i.e. stable to unstable).
39-
// When preferUnstableCannel is true in config.json, set the environment variable WEBVIEW2_RELEASE_CHANNEL_PREFERENCE
40-
// to 1 which reverses the channel search order.
41-
if (configJson.preferUnstableChannel)
42-
{
43-
SetEnvironmentVariable(L"WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", L"1");
44-
}
45-
4640
/////////////////////////////////////////////////////
4741
// Register window class
4842
WNDCLASSEX wcex;
@@ -93,7 +87,17 @@ int CALLBACK WinMain(
9387

9488
/////////////////////////////////////////////////////
9589
// Create and initialize WebView2
96-
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
90+
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
91+
92+
// The default channel search order is the WebView2 Runtime, Beta, Dev, and Canary (i.e. stable to unstable).
93+
// When preferUnstableCannel is true in config.json, set the ChannelSearchKind option to
94+
// to COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE which reverses the channel search order.
95+
if (configJson.preferUnstableChannel)
96+
{
97+
options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE);
98+
}
99+
100+
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, options.Get(),
97101
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
98102
[hWnd, configJson](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
99103

0 commit comments

Comments
 (0)