Numerous fixes for headless mode.

Remove script dom elements for internal calls.
This commit is contained in:
Lea Anthony
2019-01-13 17:54:38 +11:00
parent 0ae5381203
commit 9004c3955e
4 changed files with 17 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -157,6 +157,7 @@
return new Promise(function (resolve, reject) {
// Create a unique callbackID
debugger;
var callbackID;
do {
callbackID = bindingName + "-" + randomFunc();
@@ -202,6 +203,7 @@
function callback(incomingMessage) {
// Parse the message
var message
debugger;
try {
message = JSON.parse(incomingMessage)
} catch (e) {

View File

@@ -101,6 +101,10 @@
}
s.textContent = script;
document.head.appendChild(s)
if (script.indexOf("window.wails._.") == 0) {
var elem = document.querySelector('#' + id);
elem.parentNode.removeChild(elem);
}
}
function handleConnect() {
@@ -139,8 +143,13 @@
}, 300);
}
let idcounter = 0
function generateID() {
return "wails-" + idcounter++;
}
function handleMessage(e) {
addScript(e.data);
addScript(e.data, generateID());
}
// Key listener
@@ -169,7 +178,6 @@
connect();
}());
</script>

View File

@@ -125,16 +125,6 @@ func (h *Headless) start(conn *websocket.Conn) {
h.injectCSS(h.frameworkCSS)
}
// If given an HMTL fragment, mount it on #app
// Otherwise, replace the html tag
var injectHTML string
if h.appConfig.isHTMLFragment {
injectHTML = fmt.Sprintf("$('#app').html('%s')", h.appConfig.HTML)
} else {
injectHTML = fmt.Sprintf("$('html').html('%s')", h.appConfig.HTML)
}
h.evalJS(injectHTML)
// Inject user CSS
if h.appConfig.CSS != "" {
outputCSS := fmt.Sprintf("%.45s", h.appConfig.CSS)
@@ -274,7 +264,7 @@ func (h *Headless) NotifyEvent(event *eventData) error {
}
}
message := fmt.Sprintf("wails._.notify('%s','%s')", event.Name, data)
message := fmt.Sprintf("window.wails._.notify('%s','%s')", event.Name, data)
return h.evalJS(message)
}