start implementing messages to background APIs (text file download)

This commit is contained in:
2025-12-18 11:52:41 -06:00
parent ebf532eb07
commit 0fb529defe
3 changed files with 14 additions and 1 deletions

View File

@@ -37,7 +37,8 @@
"<all_urls>",
"storage",
"menus",
"tabs"
"tabs",
"downloads"
],
"version": "0.0",
"manifest_version": 2,

View File

@@ -1,3 +1,6 @@
(import js.html.File)
(import js.html.URL)
(defMacroVar mainKissFile kissFile)
(loadFrom "kiss-firefox" "src/kiss_firefox/Util.kiss")
(loadFrom "kiss-firefox" "src/kiss_firefox/BackgroundUtil.kiss")
@@ -10,4 +13,12 @@
(onMessage "savePad" [pad]
(WebPad.save ~pad))
(onMessage "downloadTxtFile" [filename contents]
(let [file (new File [contents] filename)
url (URL.createObjectURL file)]
(awaitLet [txtDownloadId (API.browser.downloads.download (objectWith url filename))]
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done"))))
// TODO accept and respond to messages from other extensions requesting the content of the current page's pad

View File

@@ -43,6 +43,7 @@
->e (let [interp (new KissWebPadInterp)]
(dictSet interp.globals "document" document)
(dictSet interp.globals "window" window)
(dictSet interp.globals "sendMessage" sendMessage)
(interp.evalCC (editor.getValue) ->:Void v (print v))))))
(if showing
(document.body.removeChild div)