Grammalecte  Check-in [db25c98bc2]

Overview
Comment:[fx] Use only the Sharedworker (cleanup code in background)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext_sharedworker
Files: files | file ages | folders
SHA3-256: db25c98bc2d49319935f19df8248e97f305440f7208536b6f447cb0707ee4752
User & Date: IllusionPerdu on 2017-08-10 21:20:31
Other Links: branch diff | manifest | tags
Context
2017-08-11
06:05
[fx] some code cleaning + another test check-in: b1dd1ce191 user: olr tags: fx, webext_sharedworker
2017-08-10
21:20
[fx] Use only the Sharedworker (cleanup code in background) check-in: db25c98bc2 user: IllusionPerdu tags: fx, webext_sharedworker
18:25
[fx] Fix previous commit check-in: 438b74bcdf user: IllusionPerdu tags: fx, webext_sharedworker
Changes

Modified gc_lang/fr/webext/background.js from [eb2f1b3278] to [b961377700].

1
2
3
4
5
6
7
8
9
10
11
12



13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21











-
+
+
+







// Background 

"use strict";

function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

/*
    Worker (separate thread to avoid freezing Firefox)
*/
let xGCEWorker = new Worker("gce_worker.js");
//let xGCEWorker = new Worker("gce_worker.js");
let xGCESharedWorker = new SharedWorker(browser.extension.getURL("gce_sharedworker.js"));
let xGCEWorker = xGCESharedWorker.port;

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        switch (e.data[0]) {
            case "grammar_errors":
                console.log("GRAMMAR ERRORS");
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
176
177
178
179
180
181
182

















































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        type: 'panel', url: browser.extension.getURL("panel/conjugueur.html"), top: top, left: left, width: width, height: height,
    });
    browser.windows.update(xWin.id, { top:top, left:left, }); // firefox currently ignores top and left in .create(), so move it here
    console.log("Async done");
}

//newwin();


/*
    Worker (separate thread to avoid freezing Firefox)
*/
/*
let xGCESharedWorker = new SharedWorker("gce_sharedworker.js");

xGCESharedWorker.port.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        switch (e.data[0]) {
            case "grammar_errors":
                console.log("GRAMMAR ERRORS (SHARE)");
                console.log(e.data[1].aGrammErr);
                //browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
                break;
            case "spelling_and_grammar_errors":
                console.log("SPELLING AND GRAMMAR ERRORS (SHARE)");
                console.log(e.data[1].aSpellErr);
                console.log(e.data[1].aGrammErr);
                break;
            case "text_to_test_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "options":
                console.log("OPTIONS (SHARE)");
                console.log(e.data[1]);
                break;
            case "tokens":
                console.log("TOKENS (SHARE)");
                console.log(e.data[1]);
                let xLxgTab = browser.tabs.create({
                    url: browser.extension.getURL("panel/lexicographer.html"),
                });
                xLxgTab.then(onCreated, onError);
                break;
            case "error":
                console.log("ERROR (SHARE)");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command (SHARE): " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};

console.log("Content script [worker]");
console.log(xGCESharedWorker);


//xGCESharedWorker.port.start();
//console.log("Content script [port started]");

xGCESharedWorker.port.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);

console.log("Content script [worker initialzed]");

xGCESharedWorker.port.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
//xGCESharedWorker.port.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCESharedWorker.port.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
//xGCESharedWorker.port.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCESharedWorker.port.postMessage(["fullTests"]);


*/