Fix open URI RIVM-19

This commit is contained in:
Mihail Slobodyanuk 2022-12-12 11:00:21 +02:00
parent 3aaf253ce4
commit ea0125ee1e

View file

@ -96,15 +96,26 @@ func main() {
if confui.IndexHtml == "" { if confui.IndexHtml == "" {
confui.IndexHtml = "index.html" confui.IndexHtml = "index.html"
} }
confui.IndexHtml, err = filepath.Abs(confui.IndexHtml) //Check is it URL already
if err != nil { indexUrl, err := url.ParseRequestURI(confui.IndexHtml)
panic(errors.New("Index file not found: " + err.Error())) if err != nil || len(indexUrl.Scheme) < 2 { // handling no scheme at all and windows c:\ as scheme detection
} confui.IndexHtml, err = filepath.Abs(confui.IndexHtml)
if err != nil {
if stat, err := os.Stat(confui.IndexHtml); err != nil { panic(errors.New("Index file not found: " + err.Error()))
panic(errors.New("Index file not found or permissians denied: " + err.Error())) }
} else if stat.IsDir() { if stat, err := os.Stat(confui.IndexHtml); err != nil {
panic(errors.New(fmt.Sprintf("Index file %v not found", confui.IndexHtml))) panic(errors.New("Index file not found or permissians denied: " + err.Error()))
} else if stat.IsDir() {
panic(errors.New(fmt.Sprintf("Index file %v not found", confui.IndexHtml)))
}
path_prefix := ""
if len(indexUrl.Scheme) == 1 {
path_prefix = "/"
}
indexUrl, err = url.ParseRequestURI("file://" + path_prefix + strings.ReplaceAll(confui.IndexHtml, "\\", "/"))
if err != nil {
panic(errors.New("Index file URL parse error: " + err.Error()))
}
} }
w.Bind("onLoad", func() { w.Bind("onLoad", func() {
@ -133,8 +144,8 @@ func main() {
w.Bind("ping", func(peer_list string) { w.Bind("ping", func(peer_list string) {
go ping(w, peer_list) go ping(w, peer_list)
}) })
log.Printf("Opening: %v", confui.IndexHtml) log.Printf("Opening: %v", indexUrl)
w.Navigate(confui.IndexHtml) w.Navigate(indexUrl.String())
w.Run() w.Run()
} }