Skip to content

Commit

Permalink
Add support for OpenURL to the web drivers (GopherJS and Wasm).
Browse files Browse the repository at this point in the history
Resolve issue #2736.
  • Loading branch information
Cedric BAIL committed Feb 25, 2022
1 parent 87f66cf commit 6a31f2f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
8 changes: 0 additions & 8 deletions app/app_goxjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
package app

import (
"errors"
"net/url"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
Expand All @@ -17,11 +14,6 @@ func defaultVariant() fyne.ThemeVariant {
return theme.VariantDark
}

func (app *fyneApp) OpenURL(url *url.URL) error {
// TODO #2736
return errors.New("OpenURL is not supported yet with GopherJS backend.")
}

func (app *fyneApp) SendNotification(_ *fyne.Notification) {
// TODO #2735
fyne.LogError("Sending notification is not supported yet.", nil)
Expand Down
20 changes: 20 additions & 0 deletions app/app_openurl_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build !ci && js && !wasm
// +build !ci,js,!wasm

package app

import (
"fmt"
"net/url"

"honnef.co/go/js/dom"
)

func (app *fyneApp) OpenURL(url *url.URL) error {
window := dom.GetWindow().Open(url.String(), "_blank", "")
if window == nil {
return fmt.Errorf("Unable to open a new window/tab for URL: %v.", url)
}
window.Focus()
return nil
}
19 changes: 19 additions & 0 deletions app/app_openurl_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !ci && wasm
// +build !ci,wasm

package app

import (
"fmt"
"net/url"
"syscall/js"
)

func (app *fyneApp) OpenURL(url *url.URL) error {
window := js.Global().Call("open", url.String(), "_blank", "")
if window.Equal(js.Null()) {
return fmt.Errorf("Unable to open a new window/tab for URL: %v.", url)
}
window.Call("focus")
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ require (
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2
)
1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ golang.org/x/xerrors/internal
# gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3
# honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2
## explicit
honnef.co/go/js/dom

0 comments on commit 6a31f2f

Please sign in to comment.