ADDED gc_lang/fr/webext/background.js Index: gc_lang/fr/webext/background.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/background.js @@ -0,0 +1,12 @@ +// Background + +"use strict"; + +let xGCEWorker = new Worker("gce_worker.js"); + +function handleMessage (oRequest, xSender, sendResponse) { + console.log(`[background] received: ${oRequest.content}`); + sendResponse({response: "response from background script"}); +} + +browser.runtime.onMessage.addListener(handleMessage); Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -1,11 +1,16 @@ /* - WARNING. + WORKER: + https://developer.mozilla.org/en-US/docs/Web/API/Worker + https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope + JavaScript still sucks. No module available in WebExtension at the moment! :( No require, no import/export. + + In Worker, we have importScripts() which imports everything in this scope. In order to use the same base of code with XUL-addon for Thunderbird and SDK-addon for Firefox, all modules have been “objectified”. And while they are still imported via “require” in the previous extensions, they are loaded as background scripts in WebExtension sharing the same memory space (it seems)… @@ -20,11 +25,30 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export */ +console.log("GC Engine Worker [start]"); +console.log(self); + +importScripts("grammalecte/helpers.js"); +importScripts("grammalecte/str_transform.js"); +importScripts("grammalecte/ibdawg.js"); +importScripts("grammalecte/text.js"); +importScripts("grammalecte/tokenizer.js"); +importScripts("grammalecte/fr/conj.js"); +importScripts("grammalecte/fr/mfsp.js"); +importScripts("grammalecte/fr/phonet.js"); +importScripts("grammalecte/fr/cregex.js"); +importScripts("grammalecte/fr/gc_options.js"); +importScripts("grammalecte/fr/gc_rules.js"); +importScripts("grammalecte/fr/gc_engine.js"); +importScripts("grammalecte/tests.js"); + + +helpers.echo("helpers echo"); let oTokenizer = null; let oLxg = null; function loadGrammarChecker (sGCOptions="", sContext="JavaScript") { @@ -121,17 +145,10 @@ } return JSON.stringify([]); } -function handleMessage (oRequest, xSender, sendResponse) { - console.log(`[background] received: ${oRequest.content}`); - sendResponse({response: "response from background script"}); -} - -browser.runtime.onMessage.addListener(handleMessage); - helpers.echo("START"); helpers.echo(conj.getConj("devenir", ":E", ":2s")); helpers.echo(mfsp.getMasForm("emmerdeuse", true)); @@ -145,7 +162,10 @@ gc_engine.load("JavaScript"); let aRes = gc_engine.parse("Je suit..."); for (let oErr of aRes) { helpers.echo(text.getReadableError(oErr)); } + //fullTests(); + + Index: gc_lang/fr/webext/manifest.json ================================================================== --- gc_lang/fr/webext/manifest.json +++ gc_lang/fr/webext/manifest.json @@ -28,24 +28,11 @@ "default_title": "Grammalecte [fr]", "browser_style": false }, "background": { "scripts": [ - "grammalecte/helpers.js", - "grammalecte/str_transform.js", - "grammalecte/ibdawg.js", - "grammalecte/text.js", - "grammalecte/tokenizer.js", - "grammalecte/fr/conj.js", - "grammalecte/fr/mfsp.js", - "grammalecte/fr/phonet.js", - "grammalecte/fr/cregex.js", - "grammalecte/fr/gc_options.js", - "grammalecte/fr/gc_rules.js", - "grammalecte/fr/gc_engine.js", - "grammalecte/tests.js", - "gce_worker.js" + "background.js" ] }, "web_accessible_resources": [ "grammalecte/_dictionaries/French.json", "grammalecte/fr/conj_data.json",