Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Aug 29, 2023
1 parent a0fb1b6 commit 386f2c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions pkg/edge/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "github.com/wailsapp/go-webview2/webviewloader"

type Capability string

type unsupportedCapabilityError struct {
capability Capability
}
var UnsupportedCapabilityError = &unsupportedCapabilityError{}

type unsupportedCapabilityError struct{}

func (u *unsupportedCapabilityError) Error() string {
return "unsupported capability. Requires minimum webview version " + string(u.capability)
return "unsupported capability"
}

// Capabilities is a list of capabilities with their corresponding minimum runtime version
Expand All @@ -27,7 +27,3 @@ func hasCapability(webview2RuntimeVersion string, capability Capability) bool {
}
return result >= 0
}

func UnsupportedCapabilityError(capability Capability) error {
return &unsupportedCapabilityError{capability: capability}
}
4 changes: 2 additions & 2 deletions pkg/edge/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (e *Chromium) HasCapability(c Capability) bool {

func (e *Chromium) GetIsSwipeNavigationEnabled() (bool, error) {
if !hasCapability(e.webview2RuntimeVersion, SwipeNavigation) {
return false, UnsupportedCapabilityError(SwipeNavigation)
return false, UnsupportedCapabilityError
}
webview2Settings, err := e.webview.GetSettings()
if err != nil {
Expand All @@ -503,7 +503,7 @@ func (e *Chromium) GetIsSwipeNavigationEnabled() (bool, error) {

func (e *Chromium) PutIsSwipeNavigationEnabled(enabled bool) error {
if !hasCapability(e.webview2RuntimeVersion, SwipeNavigation) {
return UnsupportedCapabilityError(SwipeNavigation)
return UnsupportedCapabilityError
}
webview2Settings, err := e.webview.GetSettings()
if err != nil {
Expand Down

0 comments on commit 386f2c3

Please sign in to comment.