diff --git a/app/c.js b/app/c.js index cc2fd33..8106940 100644 --- a/app/c.js +++ b/app/c.js @@ -16,6 +16,7 @@ function captureFrontMatterAndMarkdown() { } else if (k == "relpath") { filepath = `${location.pathname.split('/public')[0]}/content/${formData.get(k)}` gitpath = `${location.pathname.split('/public')[0]}` + publishpath = `${gitpath}/public/${formData.get(k).replace(".md", "")}/index.html` } else if (["protocol", "offline"].includes(k)) { continue } else { @@ -25,10 +26,10 @@ function captureFrontMatterAndMarkdown() { } frontmatter += "---\n" const content = document.querySelector('textarea').value - let doc = frontmatter + content + let doc = frontmatter + "\n" + content let publish = formData.get("publish") == "on" ? true : false let offline = formData.get("offline") == "on" ? true : false - return {"hugopage": doc, "filepath": filepath, "gitpath": gitpath, "publish": publish, "offline": offline, "protocol": document.location.protocol.substr(0,4)} + return {"hugopage": doc, "filepath": filepath, "gitpath": gitpath, "publishpath": publishpath, "publish": publish, "offline": offline, "protocol": document.location.protocol.substr(0,4)} } let sb = document.getElementById('sandpointsButton') @@ -36,8 +37,11 @@ if (sb) { sb.addEventListener( "click", (e)=> { e.preventDefault() - chrome.runtime.sendMessage( - captureFrontMatterAndMarkdown() - ); + pageDict = captureFrontMatterAndMarkdown() + chrome.runtime.sendMessage(pageDict) }); } + +chrome.runtime.onMessage.addListener((m, n)=> { + window.location.replace(m.msg) +}) diff --git a/app/main.js b/app/main.js index 042cda1..cae9c76 100644 --- a/app/main.js +++ b/app/main.js @@ -10,6 +10,16 @@ chrome.runtime.onMessage.addListener((m, n)=> { nh.onMessage.addListener((m, n)=> { console.log("native host message:", m) console.log("native host sender:", n) + if (m.Response != "false") { + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + chrome.tabs.sendMessage(tabs[0].id, { msg: m.response }, (response) => { + if (response) { + console.log(response) + } + }); + }) + } }) }) + diff --git a/native-host/src/main.go b/native-host/src/main.go index 772f5b9..e3e37e4 100644 --- a/native-host/src/main.go +++ b/native-host/src/main.go @@ -38,12 +38,13 @@ var bufferSize = 8192 // IncomingMessage represents a message sent to the native host. type IncomingMessage struct { - Hugopage string `json:"hugopage"` - Filepath string `json:"filepath"` - Gitpath string `json:"gitpath"` - Publish bool `json:"publish"` - Offline bool `json:"offline"` - Protocol string `json:"protocol"` + Hugopage string `json:"hugopage"` + Filepath string `json:"filepath"` + Gitpath string `json:"gitpath"` + Publishpath string `json:"publishpath"` + Publish bool `json:"publish"` + Offline bool `json:"offline"` + Protocol string `json:"protocol"` } // OutgoingMessage respresents a response to an incoming message query. @@ -207,14 +208,14 @@ func parseMessage(msg []byte) { triggerGitHook(iMsg.Gitpath, iMsg.Publish, iMsg.Offline, iMsg.Protocol) // start building outgoing json message oMsg := OutgoingMessage{ - Query: iMsg.Hugopage, + Query: iMsg.Protocol, } - switch iMsg.Hugopage { - case "foo": - oMsg.Response = "bar" + switch iMsg.Protocol { + case "file": + oMsg.Response = iMsg.Publishpath default: - oMsg.Response = "native host says yeah!" + oMsg.Response = "false" } send(oMsg) @@ -230,7 +231,7 @@ func decodeMessage(msg []byte) IncomingMessage { return iMsg } -// send sends an OutgoingMessage to os.Stdout. +// sends an OutgoingMessage to os.Stdout. func send(msg OutgoingMessage) { byteMsg := dataToBytes(msg) writeMessageLength(byteMsg) diff --git a/native-host/src/natgost b/native-host/src/natgost index ee0d71f..6a47323 100755 Binary files a/native-host/src/natgost and b/native-host/src/natgost differ