Grammalecte  Diff

Differences From Artifact [fcd118d7b1]:

To Artifact [bc6f49ada9]:


17
18
19
20
21
22
23





24

25
26
27




28
29

30
31
32
33
34
35
36
        let {sActionDone, result, dInfo, bError} = e.data;
        switch (sActionDone) {
            case "init":
                console.log("INIT DONE");
                break;
            case "parse":
                console.log("GRAMMAR ERRORS");





                console.log(result);

                break;
            case "parseAndSpellcheck":
                console.log("SPELLING AND GRAMMAR ERRORS");




                console.log(result.aSpellErr);
                console.log(result.aGrammErr);

                break;
            case "textToTest":
                console.log("TEXT TO TEXT RESULTS");
                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
                break;
            case "fullTests":
                console.log("FULL TESTS RESULTS");







>
>
>
>
>
|
>



>
>
>
>
|
|
>







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
        let {sActionDone, result, dInfo, bError} = e.data;
        switch (sActionDone) {
            case "init":
                console.log("INIT DONE");
                break;
            case "parse":
                console.log("GRAMMAR ERRORS");
                if (typeof(dInfo.iReturnPort) === "number") {
                    let xPort = aConnx[dInfo.iReturnPort];
                    xPort.postMessage(e.data);
                } else {
                    console.log("[background] don’t know where to send results");
                    console.log(e.data);
                }
                break;
            case "parseAndSpellcheck":
                console.log("SPELLING AND GRAMMAR ERRORS");
                if (typeof(dInfo.iReturnPort) === "number") {
                    let xPort = aConnx[dInfo.iReturnPort];
                    xPort.postMessage(e.data);
                } else {
                    console.log("[background] don’t know where to send results");
                    console.log(e.data);
                }
                break;
            case "textToTest":
                console.log("TEXT TO TEXT RESULTS");
                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
                break;
            case "fullTests":
                console.log("FULL TESTS RESULTS");
61
62
63
64
65
66
67







68
69
70
71
72
73


74
75
76
77
78
79
80
81
82
83
84
85
86




87
88
89
90
91
92
93
94
95





























96
97
98
99
100
101
102
        showError(e);
    }
};


xGCEWorker.postMessage({sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}, dInfo: {}});









/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
    //console.log(xSender);


    switch(oRequest.sCommand) {
        case "parse":
            xGCEWorker.postMessage({sCommand: "parse", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;
        case "parse_and_spellcheck":
            xGCEWorker.postMessage({sCommand: "parseAndSpellcheck", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;
        case "get_list_of_tokens":
            xGCEWorker.postMessage({sCommand: "getListOfTokens", dParam: {sText: oRequest.sText}, dInfo: {}});
            break;
        case "text_to_test":
            xGCEWorker.postMessage({sCommand: "textToTest", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;




        case "fulltests":
            xGCEWorker.postMessage({sCommand: "fullTests", dParam: {}, dInfo: {}});
            break;
    }
    //sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);































/*
    Context Menu
*/
browser.contextMenus.create({
    id: "grammar_checking",
    title: "Correction grammaticale",







>
>
>
>
>
>
>






>
>
|

<
<
|
<
<
|
<
<
|
<
<
>
>
>
>
|
|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


96


97


98


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        showError(e);
    }
};


xGCEWorker.postMessage({sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}, dInfo: {}});


/*
    Ports from content-scripts
*/

let aConnx = [];


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
    //console.log(xSender);
    console.log("[background] received:");
    console.log(oRequest);
    switch (oRequest.sCommand) {
        case "parse":


        case "parseAndSpellcheck":


        case "getListOfTokens":


        case "textToTest":


        case "getOptions":
        case "getDefaultOptions":
        case "setOptions":
        case "setOption":
        case "fullTests":
            xGCEWorker.postMessage(oRequest);
            break;
    }
    //sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);


function handleConnexion (p) {
    var xPort = p;
    let iPortId = aConnx.length; // identifier for the port: each port can be found at aConnx[iPortId]
    aConnx.push(xPort);
    console.log("Port: " + p.name + ", id: " + iPortId);
    xPort.onMessage.addListener(function (oRequest) {
        console.log("[background] message via connexion:");
        console.log(oRequest);
        switch (oRequest.sCommand) {
            case "getCurrentTabId":
                xPort.postMessage({sActionDone: "getCurrentTabId", result: "getCurrentTabId()", dInfo: null, bError: false});
                break;
            case "parse":
            case "parseAndSpellcheck":
            case "getListOfTokens":
                oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to received answer
                console.log(oRequest);
                xGCEWorker.postMessage(oRequest);
                break;
            default:
                console.log("[background] Unknown command: " + oRequest.sCommand);
        }
    });
    xPort.postMessage({sActionDone: "newId", result: iPortId});
}

browser.runtime.onConnect.addListener(handleConnexion);


/*
    Context Menu
*/
browser.contextMenus.create({
    id: "grammar_checking",
    title: "Correction grammaticale",
163
164
165
166
167
168
169








170
171
172
173
174
175
176
            });
            xConjTab.then(onCreated, onError);
            break;
    }    
});










async function newwin () {
    // test for popup window-like, which doesn’t close when losing the focus
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();
    const width = 710, height = 980; // the maximum size for panels is somewhere around 700x800. Firefox needs some additional pixels: 14x42 for FF54 on Win 10 with dpi 1.25
    const left = Math.round(xWindowInfo.left + xWindowInfo.width - width - 25);







>
>
>
>
>
>
>
>







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
            });
            xConjTab.then(onCreated, onError);
            break;
    }    
});


async function getCurrentTabId () {
    let xTab = await browser.tabs.getCurrent();
    return xTab.id;
}

/*
    TESTS ONLY
*/
async function newwin () {
    // test for popup window-like, which doesn’t close when losing the focus
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();
    const width = 710, height = 980; // the maximum size for panels is somewhere around 700x800. Firefox needs some additional pixels: 14x42 for FF54 on Win 10 with dpi 1.25
    const left = Math.round(xWindowInfo.left + xWindowInfo.width - width - 25);