Fix custom HTML

This commit is contained in:
Lea Anthony
2020-10-31 21:04:51 +11:00
parent 73ee9ef530
commit 1ddb74c6ce
3 changed files with 22 additions and 7 deletions

View File

@@ -1,6 +1,10 @@
package wails
import (
"fmt"
"net/url"
"strings"
"github.com/leaanthony/mewn"
"github.com/wailsapp/wails/runtime"
)
@@ -9,7 +13,6 @@ import (
type AppConfig struct {
Width, Height int
Title string
defaultHTML string
HTML string
JS string
CSS string
@@ -33,9 +36,13 @@ func (a *AppConfig) GetTitle() string {
return a.Title
}
// GetDefaultHTML returns the default HTML
func (a *AppConfig) GetDefaultHTML() string {
return a.defaultHTML
// GetHTML returns the default HTML
func (a *AppConfig) GetHTML() string {
if len(a.HTML) > 0 {
var temp = url.QueryEscape(a.HTML)
a.HTML = "data:text/html," + strings.ReplaceAll(temp, "+", "%20")
}
return a.HTML
}
// GetResizable returns true if the window should be resizable
@@ -79,6 +86,10 @@ func (a *AppConfig) merge(in *AppConfig) error {
a.JS = in.JS
}
if in.HTML != "" {
a.HTML = in.HTML
}
if in.Width != 0 {
a.Width = in.Width
}
@@ -109,5 +120,9 @@ func newConfig(userConfig *AppConfig) (*AppConfig, error) {
}
}
println("****************************************************")
fmt.Printf("%+v\n", result)
println("****************************************************")
return result, nil
}

View File

@@ -6,9 +6,9 @@ type AppConfig interface {
GetHeight() int
GetTitle() string
GetResizable() bool
GetDefaultHTML() string
GetHTML() string
GetDisableInspector() bool
GetColour() string
GetCSS() string
GetJS() string
}
}

View File

@@ -58,7 +58,7 @@ func (w *WebView) Initialise(config interfaces.AppConfig, ipc interfaces.IPCMana
Height: config.GetHeight(),
Title: config.GetTitle(),
Resizable: config.GetResizable(),
URL: config.GetDefaultHTML(),
URL: config.GetHTML(),
Debug: !config.GetDisableInspector(),
ExternalInvokeCallback: func(_ wv.WebView, message string) {
w.ipc.Dispatch(message, w.callback)