Index: gc_lang/fr/build.py ================================================================== --- gc_lang/fr/build.py +++ gc_lang/fr/build.py @@ -70,12 +70,13 @@ spfZip = "_build/" + dVars['tb_identifier'] + "-v" + dVars['version'] + '.mailext.xpi' hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) _copyGrammalecteJSPackageInZipFile(hZip, sLang) for spf in ["LICENSE.txt", "LICENSE.fr.txt"]: hZip.write(spf) - helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/gce_worker.js") helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/mailext", "", dVars, True) + helpers.addFileToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/gce_worker.js", "gce_worker.js", dVars) + helpers.addFileToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/README.md", "README.md", dVars) helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/3rd", "3rd", dVars, True) helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/_locales", "_locales", dVars, True) helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/content_scripts", "content_scripts", dVars, True) helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/fonts", "fonts", dVars, True) helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/webext/img", "img", dVars, True) Index: gc_lang/fr/mailext/background.js ================================================================== --- gc_lang/fr/mailext/background.js +++ gc_lang/fr/mailext/background.js @@ -265,18 +265,10 @@ //browser.tabs.create({url: "http://grammalecte.net"}); } }); - -/* - Ports from content-scripts -*/ - -let dConnx = new Map(); - - /* Messages from the extension (not the Worker) */ function handleMessage (oRequest, xSender, sendResponse) { // message from panels @@ -317,10 +309,15 @@ } browser.runtime.onMessage.addListener(handleMessage); +/* + Ports from content-scripts +*/ +let dConnx = new Map(); + function handleConnexion (xPort) { // Messages from tabs let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId] dConnx.set(iPortId, xPort); xPort.onMessage.addListener(function (oRequest) { @@ -364,10 +361,26 @@ xPort.postMessage({sActionDone: "init", sUrl: browser.extension.getURL("")}); } browser.runtime.onConnect.addListener(handleConnexion); + + +/* + ComposeAction + (Thunderbird only) +*/ +if (bThunderbird) { + console.log("[Grammalecte] Thunderbird: listening compose action..."); + browser.composeAction.onClicked.addListener(function (xTab, xData) { + console.log("ComposeAction clicked"); + console.log(xTab); + console.log(xData); + browser.tabs.sendMessage(xTab.id, {sActionRequest: "grammar_checker_compose_window"}); + }); +} + /* Context Menu (not for MailExtension) */ Index: gc_lang/fr/mailext/manifest.json ================================================================== --- gc_lang/fr/mailext/manifest.json +++ gc_lang/fr/mailext/manifest.json @@ -23,11 +23,11 @@ "80": "img/logo-80.png", "96": "img/logo-96.png" }, "browser_action": { "default_icon": "img/logo-32.png", - "default_title": "Grammalecte [fr]", + "default_title": "Grammalecte", "default_popup": "panel/main.html", "browser_style": false }, "compose_action": { @@ -58,10 +58,12 @@ "description": "Ouvre l’éditeur lexical" } }, "permissions": [ + "activeTab", "compose", "downloads", - "storage" + "storage", + "tabs" ] } Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -25,12 +25,16 @@ let bThunderbird = false; if (typeof(browser) !== "object") { var browser = chrome; bChrome = true; } -if (typeof(messenger) === "object") { +if (typeof(messenger) === "object" || browser.hasOwnProperty("composeAction")) { + // JS sucks again. + // In Thunderbird, exists in content-scripts, but not + // has property but is undefined... bThunderbird = true; + //console.log("[Grammalecte] Thunderbird..."); } /* function loadImage (sContainerClass, sImagePath) { let xRequest = new XMLHttpRequest(); @@ -467,10 +471,17 @@ oGrammalecte.startGCPanel(document.activeElement); } else { oGrammalecte.showMessage("Erreur. Le cadre sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel."); } break; + /* + composeAction + (Thunderbird only) + */ + case "grammar_checker_compose_window": + oGrammalecte.startGCPanel("__ThunderbirdComposeWindow__"); + break; default: console.log("[Grammalecte] Content-script. Unknown command: ", sActionDone); } }.bind(this)); }, @@ -502,28 +513,10 @@ oGrammalecteBackgroundPort.start(); -/* - ComposeAction - (Thunderbird only) -*/ -if (bThunderbird) { - console.log("Listen..."); - try { - browser.composeAction.onClicked.addListener(function (oTab, oData) { - console.log("START"); - oGrammalecte.startGCPanel("J'en aie mare..."); - }); - } - catch (e) { - showError(e) - } - console.log("Done."); -} - /* Callable API for the webpage. (Not for Thunderbird) */ Index: helpers.py ================================================================== --- helpers.py +++ helpers.py @@ -119,10 +119,11 @@ sText = Template(open(spfSrc, "r", encoding="utf-8").read()).safe_substitute(dVars) open(spfDst, "w", encoding="utf-8", newline="\n").write(sText) def addFileToZipAndFileFile (hZip, spfSrc, spfDst, dVars): + "add a file to zip archive and file it with " if spfSrc.endswith((".py", ".js", ".json", ".html", ".htm", ".css", ".xcu", ".xul", ".rdf", ".dtd", ".properties")): hZip.writestr(spfDst, fileFile(spfSrc, dVars)) else: hZip.write(spfSrc, spfDst)