mirror of
https://github.com/taigrr/wails.git
synced 2026-04-06 07:02:42 -07:00
Compare commits
3 Commits
develop
...
542-use-su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6dd999757 | ||
|
|
e572345068 | ||
|
|
1ddb74c6ce |
54
config.go
54
config.go
@@ -1,20 +1,39 @@
|
|||||||
package wails
|
package wails
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/leaanthony/mewn"
|
"github.com/leaanthony/mewn"
|
||||||
"github.com/wailsapp/wails/runtime"
|
"github.com/wailsapp/wails/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AppConfig is the configuration structure used when creating a Wails App object
|
// AppConfig is the configuration structure used when creating a Wails App object
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
Width, Height int
|
// The width and height of your application in pixels
|
||||||
Title string
|
Width, Height int
|
||||||
defaultHTML string
|
|
||||||
HTML string
|
// The title to put in the title bar
|
||||||
JS string
|
Title string
|
||||||
CSS string
|
|
||||||
Colour string
|
// The HTML your app should use. If you leave it blank, a default will be used:
|
||||||
Resizable bool
|
// <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="IE=edge" content="IE=edge"></head><body><div id="app"></div><script type="text/javascript"></script></body></html>
|
||||||
|
HTML string
|
||||||
|
|
||||||
|
// The Javascript your app should use. Normally this should be generated by a bundler.
|
||||||
|
JS string
|
||||||
|
|
||||||
|
// The CSS your app should use. Normally this should be generated by a bundler.
|
||||||
|
CSS string
|
||||||
|
|
||||||
|
// The colour of your window. Can take "#fff", "rgb(255,255,255)", "rgba(255,255,255,1)" formats
|
||||||
|
Colour string
|
||||||
|
|
||||||
|
// Indicates whether your app should be resizable
|
||||||
|
Resizable bool
|
||||||
|
|
||||||
|
// Indicated if the devtools should be disabled
|
||||||
DisableInspector bool
|
DisableInspector bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,9 +52,14 @@ func (a *AppConfig) GetTitle() string {
|
|||||||
return a.Title
|
return a.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultHTML returns the default HTML
|
// GetHTML returns the default HTML
|
||||||
func (a *AppConfig) GetDefaultHTML() string {
|
func (a *AppConfig) GetHTML() string {
|
||||||
return a.defaultHTML
|
if len(a.HTML) > 0 {
|
||||||
|
a.HTML = url.QueryEscape(a.HTML)
|
||||||
|
a.HTML = "data:text/html," + strings.ReplaceAll(a.HTML, "+", "%20")
|
||||||
|
a.HTML = strings.ReplaceAll(a.HTML, "%3D", "=")
|
||||||
|
}
|
||||||
|
return a.HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResizable returns true if the window should be resizable
|
// GetResizable returns true if the window should be resizable
|
||||||
@@ -79,6 +103,10 @@ func (a *AppConfig) merge(in *AppConfig) error {
|
|||||||
a.JS = in.JS
|
a.JS = in.JS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if in.HTML != "" {
|
||||||
|
a.HTML = in.HTML
|
||||||
|
}
|
||||||
|
|
||||||
if in.Width != 0 {
|
if in.Width != 0 {
|
||||||
a.Width = in.Width
|
a.Width = in.Width
|
||||||
}
|
}
|
||||||
@@ -109,5 +137,9 @@ func newConfig(userConfig *AppConfig) (*AppConfig, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("****************************************************")
|
||||||
|
fmt.Printf("%+v\n", result)
|
||||||
|
println("****************************************************")
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ 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
|
||||||
GetJS() string
|
GetJS() string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user