5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 03:40:45 +08:00

Allow use of custom HTML (#545)

This commit is contained in:
Lea Anthony 2020-10-29 19:57:11 +11:00 committed by GitHub
parent 5be197b68f
commit dc605c1683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,8 @@
package wails package wails
import ( import (
"github.com/leaanthony/mewn" b64 "encoding/base64"
"github.com/wailsapp/wails/runtime" "github.com/wailsapp/wails/runtime"
) )
@ -9,7 +10,6 @@ import (
type AppConfig struct { type AppConfig struct {
Width, Height int Width, Height int
Title string Title string
defaultHTML string
HTML string HTML string
JS string JS string
CSS string CSS string
@ -33,9 +33,9 @@ func (a *AppConfig) GetTitle() string {
return a.Title return a.Title
} }
// GetDefaultHTML returns the default HTML // GetHTML returns the HTML for the app
func (a *AppConfig) GetDefaultHTML() string { func (a *AppConfig) GetHTML() string {
return a.defaultHTML return "data:text/html;base64," + b64.URLEncoding.EncodeToString([]byte(a.HTML))
} }
// GetResizable returns true if the window should be resizable // GetResizable returns true if the window should be resizable
@ -75,6 +75,10 @@ func (a *AppConfig) merge(in *AppConfig) error {
a.Colour = in.Colour a.Colour = in.Colour
} }
if in.HTML != "" {
a.HTML = in.HTML
}
if in.JS != "" { if in.JS != "" {
a.JS = in.JS a.JS = in.JS
} }
@ -99,7 +103,7 @@ func newConfig(userConfig *AppConfig) (*AppConfig, error) {
Resizable: true, Resizable: true,
Title: "My Wails App", Title: "My Wails App",
Colour: "#FFF", // White by default Colour: "#FFF", // White by default
HTML: mewn.String("./runtime/assets/default.html"), HTML: defaultHTML,
} }
if userConfig != nil { if userConfig != nil {
@ -111,3 +115,17 @@ func newConfig(userConfig *AppConfig) (*AppConfig, error) {
return result, nil return result, nil
} }
var defaultHTML = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<div id="app"></div>
</body>
</html>`

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<div id="app"></div>
<script type="text/javascript">function AddScript(js, callbackID) {
var script = document.createElement('script');
script.text = js;
document.body.appendChild(script);
}</script>
</body>
</html>