From 43659cc5b308bc239d4e35b99a8e9fe5f8c47248 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 30 Nov 2024 12:02:27 +1100 Subject: [PATCH] Improved warning support. --- v3/go.mod | 4 ++-- v3/go.sum | 8 ++++---- v3/pkg/application/application.go | 11 +++++++++++ v3/pkg/application/application_options.go | 3 +++ v3/pkg/application/webview_window_windows.go | 13 +++++++++++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/v3/go.mod b/v3/go.mod index 53a1f38b322..45d678ba2a1 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -30,9 +30,9 @@ require ( github.com/pterm/pterm v0.12.51 github.com/samber/lo v1.38.1 github.com/tc-hib/winres v0.3.1 - github.com/wailsapp/go-webview2 v1.0.17 + github.com/wailsapp/go-webview2 v1.0.18-0.20241130004144-dd8667af33c1 github.com/wailsapp/mimetype v1.4.1 - golang.org/x/sys v0.22.0 + golang.org/x/sys v0.27.0 golang.org/x/term v0.20.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d gopkg.in/yaml.v3 v3.0.1 diff --git a/v3/go.sum b/v3/go.sum index 8b07497d1e1..dd369435d3d 100644 --- a/v3/go.sum +++ b/v3/go.sum @@ -219,8 +219,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tc-hib/winres v0.3.1 h1:CwRjEGrKdbi5CvZ4ID+iyVhgyfatxFoizjPhzez9Io4= github.com/tc-hib/winres v0.3.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk= -github.com/wailsapp/go-webview2 v1.0.17 h1:DkLnUKqW7J///OBXkInMq1fzC88G6ZjHwKuHXThuaco= -github.com/wailsapp/go-webview2 v1.0.17/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.18-0.20241130004144-dd8667af33c1 h1:El7t3J32//oQIsdvXAmbgeNKqgmKfKzU2SVp50yn0UM= +github.com/wailsapp/go-webview2 v1.0.18-0.20241130004144-dd8667af33c1/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= @@ -286,8 +286,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 9d575a14536..2f2f062da4a 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -344,6 +344,13 @@ type App struct { wailsEventListeners []WailsEventListener } +func (a *App) handleWarning(msg string) { + if a.options.WarningHandler != nil { + a.options.WarningHandler(msg) + } else { + a.Logger.Warn(msg) + } +} func (a *App) handleError(err error) { if a.options.ErrorHandler != nil { a.options.ErrorHandler(err) @@ -508,6 +515,10 @@ func (a *App) fatal(message string, args ...any) { err := fmt.Errorf(message, args...) a.handleFatalError(err) } +func (a *App) warning(message string, args ...any) { + msg := fmt.Sprintf(message, args...) + a.handleWarning(msg) +} func (a *App) error(message string, args ...any) { a.handleError(fmt.Errorf(message, args...)) diff --git a/v3/pkg/application/application_options.go b/v3/pkg/application/application_options.go index 3fb304badd5..171b7e8a543 100644 --- a/v3/pkg/application/application_options.go +++ b/v3/pkg/application/application_options.go @@ -106,6 +106,9 @@ type Options struct { // This is useful for implementing custom frontend-to-backend communication. RawMessageHandler func(window Window, message string) + // WarningHandler is called when a warning occurs + WarningHandler func(string) + // ErrorHandler is called when an error occurs ErrorHandler func(err error) diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index dd823f3b554..04d3597fdc7 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1503,14 +1503,23 @@ func (w *windowsWebviewWindow) setupChromium() { if opts.GeneralAutofillEnabled { err = chromium.PutIsGeneralAutofillEnabled(true) if err != nil { - globalApplication.error(err.Error()) + if errors.Is(edge.UnsupportedCapabilityError, err) { + // warning + globalApplication.warning("unsupported capability: GeneralAutofillEnabled") + } else { + globalApplication.fatal(err.Error()) + } } } if opts.PasswordAutosaveEnabled { err = chromium.PutIsPasswordAutosaveEnabled(true) if err != nil { - globalApplication.error(err.Error()) + if errors.Is(edge.UnsupportedCapabilityError, err) { + globalApplication.warning("unsupported capability: PasswordAutosaveEnabled") + } else { + globalApplication.fatal(err.Error()) + } } }