From 77ca8fe9e695a02ab96ab5ec231925fef90446cb Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 18 Aug 2023 11:06:25 +1000 Subject: [PATCH] Move webview2 options to application. Improve logging. --- v3/examples/dev/go.mod | 2 +- v3/internal/operatingsystem/os_windows.go | 1 + v3/pkg/application/application_windows.go | 16 +++++++++++----- v3/pkg/application/options_win.go | 14 +++++++------- v3/pkg/application/webview_window_windows.go | 6 +++--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/v3/examples/dev/go.mod b/v3/examples/dev/go.mod index 88ba037db..994a55b47 100644 --- a/v3/examples/dev/go.mod +++ b/v3/examples/dev/go.mod @@ -68,4 +68,4 @@ require ( mvdan.cc/sh/v3 v3.7.0 // indirect ) -replace github.com/wailsapp/wails/v3 => /Users/lea/GolandProjects/wails/v3 +replace github.com/wailsapp/wails/v3 => D:\GolandProjects\wails\v3 diff --git a/v3/internal/operatingsystem/os_windows.go b/v3/internal/operatingsystem/os_windows.go index 0926fcdc1..2e8c0775b 100644 --- a/v3/internal/operatingsystem/os_windows.go +++ b/v3/internal/operatingsystem/os_windows.go @@ -4,6 +4,7 @@ package operatingsystem import ( "fmt" + "github.com/wailsapp/wails/v3/pkg/w32" "golang.org/x/sys/windows/registry" ) diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index f98d61e30..4c0ccd428 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -5,6 +5,7 @@ package application import ( "fmt" "github.com/wailsapp/go-webview2/webviewloader" + "github.com/wailsapp/wails/v3/internal/operatingsystem" "golang.org/x/sys/windows" "os" "strconv" @@ -320,10 +321,15 @@ func newPlatformApp(app *App) *windowsApp { func (a *App) logPlatformInfo() { var args []any args = append(args, "Go-WebView2Loader", webviewloader.UsingGoWebview2Loader) - windowsVersion, err := w32.GetWindowsVersionInfo() - if err == nil { - args = append(args, "Version", windowsVersion) + webviewVersion, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(a.options.Windows.WebviewBrowserPath) + if err != nil { + args = append(args, "WebView2", "Error: "+err.Error()) + } else { + args = append(args, "WebView2", webviewVersion) } - args = append(args, "Branding", w32.GetBranding()) - a.info("Windows Info:", args...) + + osInfo, _ := operatingsystem.Info() + args = append(args, osInfo.AsLogSlice()...) + + a.info("Platform Info:", args...) } diff --git a/v3/pkg/application/options_win.go b/v3/pkg/application/options_win.go index 97890bb69..ebbf6c79a 100644 --- a/v3/pkg/application/options_win.go +++ b/v3/pkg/application/options_win.go @@ -11,6 +11,13 @@ type WindowsApplicationOptions struct { // DisableQuitOnLastWindowClosed disables the auto quit of the application if the last window has been closed. DisableQuitOnLastWindowClosed bool + + // Path where the WebView2 stores the user data. If empty %APPDATA%\[BinaryName.exe] will be used. + // If the path is not valid, a messagebox will be displayed with the error and the app will exit with error code. + WebviewUserDataPath string + + // Path to the directory with WebView2 executables. If empty WebView2 installed in the system will be used. + WebviewBrowserPath string } type BackdropType int32 @@ -41,13 +48,6 @@ type WindowsWindow struct { WindowMask []byte WindowMaskDraggable bool - // Path where the WebView2 stores the user data. If empty %APPDATA%\[BinaryName.exe] will be used. - // If the path is not valid, a messagebox will be displayed with the error and the app will exit with error code. - WebviewUserDataPath string - - // Path to the directory with WebView2 executables. If empty WebView2 installed in the system will be used. - WebviewBrowserPath string - // WebviewGpuIsDisabled is used to enable / disable GPU acceleration for the webview WebviewGpuIsDisabled bool diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 217f65069..c215f889f 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1370,7 +1370,7 @@ func (w *windowsWebviewWindow) setupChromium() { opts := w.parent.options.Windows - webview2version, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(opts.WebviewBrowserPath) + webview2version, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(globalApplication.options.Windows.WebviewBrowserPath) if err != nil { globalApplication.error("Error getting WebView2 version: " + err.Error()) return @@ -1383,8 +1383,8 @@ func (w *windowsWebviewWindow) setupChromium() { disableFeatues = append(disableFeatues, "msSmartScreenProtection") } - chromium.DataPath = opts.WebviewUserDataPath - chromium.BrowserPath = opts.WebviewBrowserPath + chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath + chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath if opts.WebviewGpuIsDisabled { chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, "--disable-gpu")