Index: gc_lang/fr/webext/gce_sharedworker.js ================================================================== --- gc_lang/fr/webext/gce_sharedworker.js +++ gc_lang/fr/webext/gce_sharedworker.js @@ -84,11 +84,11 @@ console.log(e[sParam]); } } onconnect = function (e) { - console.log("START CONNECTION"); + console.log("[Sharedworker] START CONNECTION"); xPort = e.ports[0]; xPort.onmessage = function (e) { console.log("[Sharedworker] ONMESSAGE"); let {sCommand, dParam, dInfo} = e.data; @@ -133,35 +133,41 @@ } } //xPort.start(); } +let bInitDone = false; let oDict = null; let oTokenizer = null; let oLxg = null; let oTest = null; function init (sExtensionPath, sGCOptions="", sContext="JavaScript", dInfo={}) { try { - console.log("Loading… Extension path: " + sExtensionPath); - conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json")); - phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json")); - mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json")); - console.log("Modules have been initialized…"); - gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries"); - oDict = gc_engine.getDictionary(); - oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json"); - oLxg = new Lexicographe(oDict); - if (sGCOptions !== "") { - gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions))); - } - oTokenizer = new Tokenizer("fr"); - //tests(); - // we always retrieve options from the gc_engine, for setOptions filters obsolete options - //xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]); + if (!bInitDone) { + console.log("[Sharedworker] Loading… Extension path: " + sExtensionPath); + conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json")); + phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json")); + mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json")); + console.log("[Sharedworker] Modules have been initialized…"); + gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries"); + oDict = gc_engine.getDictionary(); + oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json"); + oLxg = new Lexicographe(oDict); + if (sGCOptions !== "") { + gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions))); + } + oTokenizer = new Tokenizer("fr"); + //tests(); + // we always retrieve options from the gc_engine, for setOptions filters obsolete options + //xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]); + bInitDone = true; + } else { + console.log("[Sharedworker] Already initialized…") + } xPort.postMessage(createResponse("init", gc_engine.getOptions().gl_toString(), dInfo)); } catch (e) { helpers.logerror(e); xPort.postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true)); @@ -220,11 +226,11 @@ } } function textToTest (sText, sCountry, bDebug, bContext, dInfo={}) { if (!gc_engine || !oDict) { - xPort.postMessage(["error", "# Error: grammar checker or dictionary not loaded."]); + xPort.postMessage(createResponse("textToTest", "# Grammar checker or dictionary not loaded.", dInfo)); return; } let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext); let sMsg = ""; for (let oErr of aGrammErr) { @@ -234,11 +240,11 @@ xPort.postMessage(createResponse("textToTest", sMsg, dInfo)); } function fullTests (sGCOptions="", dInfo={}) { if (!gc_engine || !oDict) { - xPort.postMessage(["error", "# Error: grammar checker or dictionary not loaded."]); + xPort.postMessage(createResponse("fullTests", "# Grammar checker or dictionary not loaded.", dInfo)); return; } let dMemoOptions = gc_engine.getOptions(); if (sGCOptions) { gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));