Skip to content

Commit 35b8560

Browse files
Merge pull request #47 from francisbouvier/master
Add checkUrl before NewWindow
2 parents 51010ab + cb4a050 commit 35b8560

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lib/bindings/window/window.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package window
33
import (
44
"errors"
55
"fmt"
6+
"net/url"
7+
"path/filepath"
68
"time"
79

810
"github.com/miketheprogrammer/go-thrust/lib/bindings/session"
@@ -27,9 +29,29 @@ type Window struct {
2729
SendChannel *connection.In `json:"-"`
2830
}
2931

30-
func NewWindow(url string, sess *session.Session) *Window {
32+
func checkUrl(s string) (string, error) {
33+
u, err := url.Parse(s)
34+
if err != nil {
35+
return s, err
36+
}
37+
if u.Scheme == "" {
38+
p, err := filepath.Abs(s)
39+
if err != nil {
40+
return s, err
41+
}
42+
u = &url.URL{
43+
Scheme: "file",
44+
Path: p,
45+
}
46+
}
47+
return u.String(), err
48+
}
49+
50+
func NewWindow(s string, sess *session.Session) *Window {
51+
u, _ := checkUrl(s)
52+
3153
w := Window{}
32-
w.Url = url
54+
w.Url = u
3355
if len(w.Url) == 0 {
3456
w.Url = "http://google.com"
3557
}

0 commit comments

Comments
 (0)