Skip to content

Commit 381fa8b

Browse files
committed
Add hostingMode config option
1 parent 3b8804a commit 381fa8b

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/Config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ConfigJson LoadConfigJson(const std::string& path)
1212
ret.startUrl = "https://github.com/WebView-CG/CanIWebView2";
1313
ret.preferUnstableChannel = false;
1414
ret.additionalBrowserArguments = "";
15+
ret.hostingMode = "";
1516

1617
// If file does not exist, just use defaults
1718
if (!FileExists(path))
@@ -39,5 +40,8 @@ ConfigJson LoadConfigJson(const std::string& path)
3940
if (parsedJson.contains("additionalBrowserArguments"))
4041
ret.additionalBrowserArguments = parsedJson["additionalBrowserArguments"].get<std::string>();
4142

43+
if (parsedJson.contains("hostingMode"))
44+
ret.hostingMode = parsedJson["hostingMode"].get<std::string>();
45+
4246
return ret;
4347
}

src/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct ConfigJson {
66
std::string startUrl;
77
bool preferUnstableChannel;
88
std::string additionalBrowserArguments;
9+
std::string hostingMode;
910
};
1011

1112
ConfigJson LoadConfigJson(const std::string& path);

src/WebView.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ int CALLBACK WinMain(
3737
std::string configJsonPath = FolderFromPath(GetModulePath()) + "config.json";
3838
ConfigJson configJson = LoadConfigJson(configJsonPath);
3939

40+
// If config.json specifies the hosting mode as "window-to-visual", force this hosting mode by setting the
41+
// environment variable COREWEBVIEW2_FORCED_HOSTING_MODE to COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL.
42+
// See: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/windowed-vs-visual-hosting
43+
if (configJson.hostingMode == "window-to-visual")
44+
{
45+
SetEnvironmentVariable(L"COREWEBVIEW2_FORCED_HOSTING_MODE", L"COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL");
46+
}
47+
4048
/////////////////////////////////////////////////////
4149
// Register window class
4250
WNDCLASSEX wcex;

0 commit comments

Comments
 (0)