mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 07:52:12 +08:00
Merge pull request #29 from wailsapp/Move-headless-capability-into-own-library
Move headless capability into own library
This commit is contained in:
commit
cd8b4f088f
@ -127,6 +127,58 @@ func (h *Headless) sendMessage(conn *websocket.Conn, msg string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Headless) injectAllFiles() {
|
||||||
|
// Inject Framework
|
||||||
|
if h.frameworkJS != "" {
|
||||||
|
h.evalJS(h.frameworkJS, jsMessage)
|
||||||
|
}
|
||||||
|
if h.frameworkCSS != "" {
|
||||||
|
h.injectCSS(h.frameworkCSS)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject user CSS
|
||||||
|
if h.appConfig.CSS != "" {
|
||||||
|
outputCSS := fmt.Sprintf("%.45s", h.appConfig.CSS)
|
||||||
|
if len(outputCSS) > 45 {
|
||||||
|
outputCSS += "..."
|
||||||
|
}
|
||||||
|
h.log.DebugFields("Inject User CSS", Fields{"css": outputCSS})
|
||||||
|
h.injectCSS(h.appConfig.CSS)
|
||||||
|
} else {
|
||||||
|
// Use default wails css
|
||||||
|
h.log.Debug("Injecting Default Wails CSS")
|
||||||
|
defaultCSS := BoxString(&defaultAssets, "wails.css")
|
||||||
|
|
||||||
|
h.injectCSS(defaultCSS)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject all the CSS files that have been added
|
||||||
|
for _, css := range h.cssCache {
|
||||||
|
h.injectCSS(css)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject all the JS files that have been added
|
||||||
|
for _, js := range h.jsCache {
|
||||||
|
h.evalJS(js, jsMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject user JS
|
||||||
|
if h.appConfig.JS != "" {
|
||||||
|
outputJS := fmt.Sprintf("%.45s", h.appConfig.JS)
|
||||||
|
if len(outputJS) > 45 {
|
||||||
|
outputJS += "..."
|
||||||
|
}
|
||||||
|
h.log.DebugFields("Inject User JS", Fields{"js": outputJS})
|
||||||
|
h.evalJS(h.appConfig.JS, jsMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
var injectHTML string
|
||||||
|
if h.appConfig.isHTMLFragment {
|
||||||
|
injectHTML = fmt.Sprintf("$('#app').html('%s')", h.appConfig.HTML)
|
||||||
|
h.evalJS(injectHTML, htmlMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Headless) start(conn *websocket.Conn) {
|
func (h *Headless) start(conn *websocket.Conn) {
|
||||||
|
|
||||||
// set external.invoke
|
// set external.invoke
|
||||||
@ -152,58 +204,9 @@ func (h *Headless) start(conn *websocket.Conn) {
|
|||||||
h.evalJS(binding, bindingMessage)
|
h.evalJS(binding, bindingMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// In Bridge mode, we only send the wails runtime and bindings
|
// In standard headless mode, we send all of the files
|
||||||
// so ignore this whole section
|
|
||||||
if !h.bridgeMode {
|
if !h.bridgeMode {
|
||||||
// Inject Framework
|
h.injectAllFiles()
|
||||||
if h.frameworkJS != "" {
|
|
||||||
h.evalJS(h.frameworkJS, jsMessage)
|
|
||||||
}
|
|
||||||
if h.frameworkCSS != "" {
|
|
||||||
h.injectCSS(h.frameworkCSS)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject user CSS
|
|
||||||
if h.appConfig.CSS != "" {
|
|
||||||
outputCSS := fmt.Sprintf("%.45s", h.appConfig.CSS)
|
|
||||||
if len(outputCSS) > 45 {
|
|
||||||
outputCSS += "..."
|
|
||||||
}
|
|
||||||
h.log.DebugFields("Inject User CSS", Fields{"css": outputCSS})
|
|
||||||
h.injectCSS(h.appConfig.CSS)
|
|
||||||
} else {
|
|
||||||
// Use default wails css
|
|
||||||
h.log.Debug("Injecting Default Wails CSS")
|
|
||||||
defaultCSS := BoxString(&defaultAssets, "wails.css")
|
|
||||||
|
|
||||||
h.injectCSS(defaultCSS)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject all the CSS files that have been added
|
|
||||||
for _, css := range h.cssCache {
|
|
||||||
h.injectCSS(css)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject all the JS files that have been added
|
|
||||||
for _, js := range h.jsCache {
|
|
||||||
h.evalJS(js, jsMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject user JS
|
|
||||||
if h.appConfig.JS != "" {
|
|
||||||
outputJS := fmt.Sprintf("%.45s", h.appConfig.JS)
|
|
||||||
if len(outputJS) > 45 {
|
|
||||||
outputJS += "..."
|
|
||||||
}
|
|
||||||
h.log.DebugFields("Inject User JS", Fields{"js": outputJS})
|
|
||||||
h.evalJS(h.appConfig.JS, jsMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
var injectHTML string
|
|
||||||
if h.appConfig.isHTMLFragment {
|
|
||||||
injectHTML = fmt.Sprintf("$('#app').html('%s')", h.appConfig.HTML)
|
|
||||||
h.evalJS(injectHTML, htmlMessage)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit that everything is loaded and ready
|
// Emit that everything is loaded and ready
|
||||||
|
Loading…
Reference in New Issue
Block a user