Grammalecte  Check-in [08f0167b9e]

Overview
Comment:[fx] Correct the intialisation of the SharedWorker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 08f0167b9e245faad3b3ca7db8fb74ab9e409d691a50abb57917f9713cf89142
User & Date: IllusionPerdu on 2017-08-09 19:33:27
Other Links: branch diff | manifest | tags
Context
2017-08-10
14:08
Create new branch named "webext_sharedworker" check-in: 976290fcbe user: IllusionPerdu tags: webext_sharedworker
09:59
[fx] content-script interface + remove SharedWorker check-in: e026bff1c5 user: olr tags: fx, webext2
2017-08-09
19:33
[fx] Correct the intialisation of the SharedWorker check-in: 08f0167b9e user: IllusionPerdu tags: fx, webext2
18:11
[fx] SharedWorker attempt (not working in content script) + lexicographer panel check-in: 4e34f03093 user: olr tags: fx, webext2
Changes

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

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
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







-
+




-
+




-
+



-
+



-
+



-
+







-
+



-
+







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");
                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");
                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");
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS");
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "options":
                console.log("OPTIONS");
                console.log("OPTIONS (SHARE)");
                console.log(e.data[1]);
                break;
            case "tokens":
                console.log("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");
                console.log("ERROR (SHARE)");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command: " + e.data[0]);
                console.log("Unknown command (SHARE): " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};

Modified gc_lang/fr/webext/content_scripts/modify_page.js from [a278d60ca9] to [a5f9d0af95].

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

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36

37
38
39
40
41

42
43
44
45

46
47
48
49

50
51
52
53

54
55
56
57
58
59
60
61

62
63
64
65

66
67
68
69
70
71
72
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35

36
37
38
39
40

41
42
43
44

45
46
47
48

49
50
51
52

53
54
55
56
57
58
59
60

61
62
63
64

65
66
67
68
69
70
71
72













-
+
















-
+




-
+




-
+



-
+



-
+



-
+







-
+



-
+







// Modify page

"use strict";

console.log("Content script [start]");

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 SharedWorker("../gce_sharedworker.js");
let xGCEWorker = new SharedWorker(browser.extension.getURL("../gce_sharedworker.js"));

xGCEWorker.onerror = function(e) {
    console.log('There is an error with your worker!');
    console.log(typeof(e));
    console.log(e);
    for (let sParam in e) {
        console.log(sParam);
        console.log(e.sParam);
    }
}

xGCEWorker.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");
                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");
                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");
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS");
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "options":
                console.log("OPTIONS");
                console.log("OPTIONS (SHARE)");
                console.log(e.data[1]);
                break;
            case "tokens":
                console.log("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");
                console.log("ERROR (SHARE)");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command: " + e.data[0]);
                console.log("Unknown command (SHARE): " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};