mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Improved warning support.
This commit is contained in:
parent
d27e75c57f
commit
43659cc5b3
5 changed files with 31 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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=
|
||||
|
|
|
|||
|
|
@ -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...))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue