Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -22,11 +22,16 @@ let xGCEWorker = new Worker("gce_worker.js"); xGCEWorker.onmessage = function (e) { // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent try { - let {sActionDone, result, dInfo} = e.data; + let {sActionDone, result, dInfo, bEnd, bError} = e.data; + if (bError) { + console.log(result); + console.log(dInfo); + return; + } switch (sActionDone) { case "init": storeGCOptions(result); break; case "parse": @@ -84,10 +89,14 @@ } } function initGrammarChecker (dSavedOptions) { let dOptions = (dSavedOptions.hasOwnProperty("gc_options")) ? dSavedOptions.gc_options : null; + if (bChrome) { + // JS crap again. Chrome can’t store Map object. + dOptions = helpers.objectToMap(dOptions); + } xGCEWorker.postMessage({ sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, dInfo: {} }); @@ -99,11 +108,11 @@ sCommand: "setDictionary", dParam: { sType: "extended", oDict: dSavedDictionary["oExtendedDictionary"] }, dInfo: {} }); } - else if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) { + if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) { xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sType: "personal", oDict: dSavedDictionary["oPersonalDictionary"] }, dInfo: {} }); Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -88,11 +88,11 @@ */ onmessage = function (e) { let {sCommand, dParam, dInfo} = e.data; switch (sCommand) { case "init": - init(dParam.sExtensionPath, dParam.sOptions, dParam.sContext, dInfo); + init(dParam.sExtensionPath, dParam.dOptions, dParam.sContext, dInfo); break; case "parse": parse(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); break; case "parseAndSpellcheck": @@ -171,10 +171,11 @@ oLocution = helpers.loadFile(sExtensionPath + "/grammalecte/fr/locutions_data.json"); oLxg = new Lexicographe(oSpellChecker, oTokenizer, oLocution); if (dOptions !== null) { + console.log(dOptions); gc_engine.setOptions(dOptions); } //tests(); bInitDone = true; } else { @@ -231,12 +232,14 @@ postMessage(createResponse("setOptions", gc_engine.getOptions(), dInfo, true)); } function setOption (sOptName, bValue, dInfo={}) { console.log(sOptName+": "+bValue); - gc_engine.setOptions(new Map([ [sOptName, bValue] ])); - postMessage(createResponse("setOption", gc_engine.getOptions(), dInfo, true)); + if (sOptName) { + gc_engine.setOption(sOptName, bValue); + postMessage(createResponse("setOption", gc_engine.getOptions(), dInfo, true)); + } } function resetOptions (dInfo={}) { gc_engine.resetOptions(); postMessage(createResponse("resetOptions", gc_engine.getOptions(), dInfo, true)); Index: gc_lang/fr/webext/panel/main.js ================================================================== --- gc_lang/fr/webext/panel/main.js +++ gc_lang/fr/webext/panel/main.js @@ -45,15 +45,17 @@ dParam: {}, dInfo: {} }); } else if (xElem.id.startsWith("option_")) { - browser.runtime.sendMessage({ - sCommand: "setOption", - dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, - dInfo: {} - }); + if (xElem.dataset.option) { + browser.runtime.sendMessage({ + sCommand: "setOption", + dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, + dInfo: {} + }); + } } else if (xElem.id.startsWith("ui_option_")) { storeUIOptions(); } else if (xElem.id.startsWith("link_")) { @@ -208,20 +210,22 @@ setGCOptions(dSavedOptions.gc_options); } } function setGCOptions (dOptions) { - // dOptions is supposed to be a Map - if (bChrome) { - // JS crap again. Chrome can’t store/send Map object. - let m = new Map(); - for (let param in dOptions) { - m.set(param, dOptions[param]); - } - dOptions = m; - } - for (let [sOpt, bVal] of dOptions) { - if (document.getElementById("option_"+sOpt)) { - document.getElementById("option_"+sOpt).checked = bVal; - } + try { + // dOptions is supposed to be a Map + if (bChrome) { + // JS crap again. Chrome can’t store/send Map object. + dOptions = helpers.objectToMap(dOptions); + } + for (let [sOpt, bVal] of dOptions) { + if (document.getElementById("option_"+sOpt)) { + document.getElementById("option_"+sOpt).checked = bVal; + } + } + } + catch (e) { + console.log(dOptions); + showError(e); } }