From 0fb529defee637784032319d295de9b7bf4eed5a Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 18 Dec 2025 11:52:41 -0600 Subject: [PATCH] start implementing messages to background APIs (text file download) --- manifest.json | 3 ++- src/kiss_web_pad/Background_.kiss | 11 +++++++++++ src/kiss_web_pad/Main_.kiss | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 03e932c..d302383 100644 --- a/manifest.json +++ b/manifest.json @@ -37,7 +37,8 @@ "", "storage", "menus", - "tabs" + "tabs", + "downloads" ], "version": "0.0", "manifest_version": 2, diff --git a/src/kiss_web_pad/Background_.kiss b/src/kiss_web_pad/Background_.kiss index 9ae4866..cc4a12d 100644 --- a/src/kiss_web_pad/Background_.kiss +++ b/src/kiss_web_pad/Background_.kiss @@ -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 \ No newline at end of file diff --git a/src/kiss_web_pad/Main_.kiss b/src/kiss_web_pad/Main_.kiss index befcd0a..836edf6 100644 --- a/src/kiss_web_pad/Main_.kiss +++ b/src/kiss_web_pad/Main_.kiss @@ -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)