5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 18:00:02 +08:00

[windows] Add support for AdditionalBrowserArgs to the legacy Webview2Loader (#2267)

This commit is contained in:
stffabi 2023-01-02 22:41:56 +01:00 committed by GitHub
parent ef5f547d27
commit ebc653a584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -26,8 +26,8 @@ func createCoreWebView2EnvironmentWithOptions(browserExecutableFolder, userDataF
hr, err := webviewloader.CreateCoreWebView2EnvironmentWithOptions( hr, err := webviewloader.CreateCoreWebView2EnvironmentWithOptions(
browserPathPtr, browserPathPtr,
userPathPtr, userPathPtr,
0,
uintptr(unsafe.Pointer(environmentCompletedHandle)), uintptr(unsafe.Pointer(environmentCompletedHandle)),
additionalBrowserArgs,
) )
if hr != 0 { if hr != 0 {

View File

@ -15,7 +15,7 @@ import (
) )
func init() { func init() {
preventEnvAndRegistryOverrides(nil, nil) preventEnvAndRegistryOverrides(nil, nil, "")
} }
var ( var (
@ -97,7 +97,7 @@ func GetAvailableCoreWebView2BrowserVersionString(path string) (string, error) {
} }
} }
preventEnvAndRegistryOverrides(browserPath, nil) preventEnvAndRegistryOverrides(browserPath, nil, "")
var result *uint16 var result *uint16
res, _, err := memGetAvailableCoreWebView2BrowserVersionString.Call( res, _, err := memGetAvailableCoreWebView2BrowserVersionString.Call(
uint64(uintptr(unsafe.Pointer(browserPath))), uint64(uintptr(unsafe.Pointer(browserPath))),
@ -119,17 +119,17 @@ func GetAvailableCoreWebView2BrowserVersionString(path string) (string, error) {
// CreateCoreWebView2EnvironmentWithOptions tries to load WebviewLoader2 and // CreateCoreWebView2EnvironmentWithOptions tries to load WebviewLoader2 and
// call the CreateCoreWebView2EnvironmentWithOptions routine. // call the CreateCoreWebView2EnvironmentWithOptions routine.
func CreateCoreWebView2EnvironmentWithOptions(browserExecutableFolder, userDataFolder *uint16, environmentOptions uintptr, environmentCompletedHandle uintptr) (uintptr, error) { func CreateCoreWebView2EnvironmentWithOptions(browserExecutableFolder, userDataFolder *uint16, environmentCompletedHandle uintptr, additionalBrowserArgs string) (uintptr, error) {
err := loadFromMemory() err := loadFromMemory()
if err != nil { if err != nil {
return 0, err return 0, err
} }
preventEnvAndRegistryOverrides(browserExecutableFolder, userDataFolder) preventEnvAndRegistryOverrides(browserExecutableFolder, userDataFolder, additionalBrowserArgs)
res, _, _ := memCreate.Call( res, _, _ := memCreate.Call(
uint64(uintptr(unsafe.Pointer(browserExecutableFolder))), uint64(uintptr(unsafe.Pointer(browserExecutableFolder))),
uint64(uintptr(unsafe.Pointer(userDataFolder))), uint64(uintptr(unsafe.Pointer(userDataFolder))),
uint64(environmentOptions), 0,
uint64(environmentCompletedHandle), uint64(environmentCompletedHandle),
) )
return uintptr(res), nil return uintptr(res), nil
@ -151,13 +151,13 @@ func loadFromMemory() error {
return err return err
} }
func preventEnvAndRegistryOverrides(browserFolder, userDataFolder *uint16) { func preventEnvAndRegistryOverrides(browserFolder, userDataFolder *uint16, additionalBrowserArgs string) {
// Setting these env variables to empty string also prevents registry overrides because webview2loader // Setting these env variables to empty string also prevents registry overrides because webview2loader
// checks for existence and not for empty value // checks for existence and not for empty value
os.Setenv("WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER", "") os.Setenv("WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER", "")
os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "")
// Set these overrides to the values or empty to prevent registry and external env overrides // Set these overrides to the values or empty to prevent registry and external env overrides
os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", additionalBrowserArgs)
os.Setenv("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "0") os.Setenv("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "0")
os.Setenv("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", windows.UTF16PtrToString(browserFolder)) os.Setenv("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", windows.UTF16PtrToString(browserFolder))
os.Setenv("WEBVIEW2_USER_DATA_FOLDER", windows.UTF16PtrToString(userDataFolder)) os.Setenv("WEBVIEW2_USER_DATA_FOLDER", windows.UTF16PtrToString(userDataFolder))