Grammalecte  Check-in [7bf95d9332]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[fx] buttons to stop and restart the worker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256:7bf95d9332c59248aa8c7039e4f67ae77f51f8aa43921a9ed523736f14f0b938
User & Date: olr 2019-08-10 10:56:05
Context
2019-08-10
11:08
[fr] version 1.3 check-in: e13493c3a8 user: olr tags: fr, trunk
10:56
[fx] buttons to stop and restart the worker check-in: 7bf95d9332 user: olr tags: fx, trunk
2019-08-09
10:02
[fx] new initialization for background and worker check-in: 0d2811ed48 user: olr tags: fx, trunk
Changes

Changes to gc_lang/fr/webext/background.js.

    89     89       },
    90     90   
    91     91       getTimeSinceLastResponse: function () {
    92     92           // result in seconds
    93     93           return Math.floor((Date.now() - this.nLastTimeWorkerResponse) / 1000);
    94     94       },
    95     95   
    96         -    restart: function () {
    97         -        if (this.getTimeSinceLastResponse() <= 5) {
           96  +    restart: function (nDelay=5) {
           97  +        if (this.getTimeSinceLastResponse() <= nDelay) {
           98  +            console.log("Worker not restarted. Worked ", nDelay, " seconds ago.");
    98     99               return false;
    99    100           }
   100    101           if (this.xGCEWorker) {
   101    102               this.xGCEWorker.terminate();
   102    103           }
   103    104           this.start();
   104    105           oInitHandler.initGrammarChecker();
          106  +        sendCommandToAllTabs("workerRestarted");
          107  +        console.log("Worker restarted.");
   105    108           return true;
   106    109       },
   107    110   
   108    111       addTask: function () {
   109    112           //
   110    113       },
   111    114   
................................................................................
   243    246           case "resetOptions":
   244    247           case "textToTest":
   245    248           case "fullTests":
   246    249           case "setDictionary":
   247    250           case "setDictionaryOnOff":
   248    251               oWorkerHandler.xGCEWorker.postMessage(oRequest);
   249    252               break;
          253  +        case "restartWorker":
          254  +            oWorkerHandler.restart(dParam["nDelayLimit"]);
          255  +            break;
   250    256           case "openURL":
   251    257               browser.tabs.create({url: dParam.sURL});
   252    258               break;
   253    259           case "openConjugueurTab":
   254    260               openConjugueurTab();
   255    261               break;
   256    262           case "openLexiconEditor":
................................................................................
   282    288               case "parseFull":
   283    289               case "getListOfTokens":
   284    290               case "getSpellSuggestions":
   285    291               case "getVerb":
   286    292                   oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer
   287    293                   oWorkerHandler.xGCEWorker.postMessage(oRequest);
   288    294                   break;
          295  +            case "restartWorker":
          296  +                oWorkerHandler.restart(dParam["nDelayLimit"]);
          297  +                break;
   289    298               case "openURL":
   290    299                   browser.tabs.create({url: dParam.sURL});
   291    300                   break;
   292    301               case "openConjugueurTab":
   293    302                   openConjugueurTab();
   294    303                   break;
   295    304               case "openConjugueurWindow":
................................................................................
   438    447       browser.tabs.query({ currentWindow: true, active: true }).then((lTabs) => {
   439    448           for (let xTab of lTabs) {
   440    449               console.log(xTab);
   441    450               browser.tabs.sendMessage(xTab.id, {sActionRequest: sCommand});
   442    451           }
   443    452       }, showError);
   444    453   }
          454  +
          455  +function sendCommandToAllTabs (sCommand) {
          456  +    for (let [iTab, xTabPort] of dConnx.entries()) {
          457  +        xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
          458  +    }
          459  +}
   445    460   
   446    461   function openLexiconEditor (sName="__personal__") {
   447    462       if (nTabLexiconEditor === null) {
   448    463           if (bChrome) {
   449    464               browser.tabs.create({
   450    465                   url: browser.extension.getURL("panel/lex_editor.html")
   451    466               }, onLexiconEditorOpened);

Changes to gc_lang/fr/webext/content_scripts/init.js.

   299    299               oGrammalecte.observePage();
   300    300               break;
   301    301           case "parseAndSpellcheck":
   302    302               if (!bEnd) {
   303    303                   oGrammalecte.oGCPanel.addParagraphResult(result);
   304    304               } else {
   305    305                   oGrammalecte.oGCPanel.stopWaitIcon();
          306  +                oGrammalecte.oGCPanel.endTimer();
   306    307               }
   307    308               break;
   308    309           case "parseAndSpellcheck1":
   309    310               oGrammalecte.oGCPanel.refreshParagraph(dInfo.sParagraphId, result);
   310    311               break;
   311    312           case "parseFull":
   312    313               // TODO
   313    314               break;
   314    315           case "getListOfTokens":
   315    316               if (!bEnd) {
   316    317                   oGrammalecte.oGCPanel.addListOfTokens(result);
   317    318               } else {
   318    319                   oGrammalecte.oGCPanel.stopWaitIcon();
          320  +                oGrammalecte.oGCPanel.endTimer();
   319    321               }
   320    322               break;
   321    323           case "getSpellSuggestions":
   322    324               oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, dInfo.sErrorId);
   323    325               break;
   324    326           case "getVerb":
   325    327               if (dInfo.bStart) {
   326    328                   oGrammalecte.oGCPanel.conjugateWith(result.oVerb, result.oConjTable);
   327    329               } else {
   328    330                   oGrammalecte.oGCPanel.displayConj(result.oConjTable);
   329    331               }
   330    332               break;
          333  +        case "workerRestarted":
          334  +            oGrammalecte.oGCPanel.stopWaitIcon();
          335  +            oGrammalecte.oGCPanel.showMessage("Le serveur grammatical a été arrêté et relancé.");
          336  +            break;
   331    337           /*
   332    338               Commands received from the context menu
   333    339               (Context menu are initialized in background)
   334    340           */
   335    341           // Grammar checker commands
   336    342           case "grammar_checker_editable":
   337    343               if (oGrammalecte.xRightClickedNode !== null) {

Changes to gc_lang/fr/webext/content_scripts/panel.css.

   174    174       border-top: 2px solid;
   175    175       border-bottom: 2px solid;
   176    176       border-color: hsl(60, 90%, 50%);
   177    177       color: hsl(60, 10%, 40%);
   178    178       font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif;
   179    179       font-size: 14px;
   180    180       hyphens: auto;
          181  +}
          182  +div#grammalecte_panel_message_action_button {
          183  +    margin: 10px;
          184  +    padding: 4px 10px;
          185  +    border-radius: 5px;
          186  +    background-color: hsl(30, 100%, 50%);
          187  +    color: hsl(30, 60%, 95%);
          188  +    font-size: 14px;
          189  +    font-weight: bold;
          190  +    cursor: pointer;
          191  +}
          192  +div#grammalecte_panel_message_close_button:hover {
          193  +    background-color: hsl(0, 100%, 60%);
          194  +    color: hsl(0, 50%, 100%);
   181    195   }
   182    196   div#grammalecte_panel_message_close_button {
   183    197       float: right;
   184    198       margin: 0 0 10px 10px;
   185    199       padding: 2px 5px;
   186    200       border-radius: 5px;
   187    201       background-color: hsl(60, 90%, 50%);

Changes to gc_lang/fr/webext/content_scripts/panel.js.

   112    112   
   113    113       _createMesssageBlock () {
   114    114           this.xPanelMessageBlock = oGrammalecte.createNode("div", {id: "grammalecte_panel_message_block"});
   115    115           let xPanelMessageCloseButton = oGrammalecte.createNode("div", {id: "grammalecte_panel_message_close_button", textContent: "×"});
   116    116           xPanelMessageCloseButton.onclick = () => { this.hideMessage() };
   117    117           this.xPanelMessageBlock.appendChild(xPanelMessageCloseButton);
   118    118           this.xPanelMessage = oGrammalecte.createNode("div", {id: "grammalecte_panel_message"});
          119  +        this.xPanelMessageActionButton = oGrammalecte.createNode("div", {id: "grammalecte_panel_message_action_button"});
   119    120           this.xPanelMessageBlock.appendChild(this.xPanelMessage);
          121  +        this.xPanelMessageBlock.appendChild(this.xPanelMessageActionButton);
   120    122       }
   121    123   
   122    124       insertIntoPage () {
   123    125           if (this.bShadow) {
   124    126               oGrammalecte.createStyle("content_scripts/panel.css", null, this.xShadow);
   125    127               oGrammalecte.createStyle("content_scripts/panel_gc.css", null, this.xShadow);
   126    128               oGrammalecte.createStyle("content_scripts/panel_lxg.css", null, this.xShadow);
................................................................................
   245    247       }
   246    248   
   247    249       stopWaitIcon () {
   248    250           this.bWorking = false;
   249    251           this.xWaitIcon.style.visibility = "hidden";
   250    252       }
   251    253   
   252         -    showMessage (sMessage) {
          254  +    showMessage (sMessage, sActionMessage="", sActionName="") {
   253    255           this.xPanelMessageBlock.style.display = "block";
   254    256           this.xPanelMessage.textContent = sMessage;
          257  +        if (sActionMessage) {
          258  +            this.xPanelMessageActionButton.textContent = sActionMessage;
          259  +            this.xPanelMessageActionButton.style.display = "block";
          260  +            this.xPanelMessageActionButton.onclick = () => { this.executeButtonAction(sActionName); };
          261  +        } else {
          262  +            this.xPanelMessageActionButton.style.display = "none";
          263  +        }
   255    264       }
   256    265   
   257    266       hideMessage () {
   258    267           this.xPanelMessageBlock.style.display = "none";
          268  +        this.xPanelMessageActionButton.style.display = "none";
          269  +    }
          270  +
          271  +    executeButtonAction (sActionName) {
          272  +        switch (sActionName) {
          273  +            case "":
          274  +                break;
          275  +            case "restartWorker":
          276  +                xGrammalectePort.postMessage({
          277  +                    sCommand: "restartWorker",
          278  +                    dParam: { "nTimeDelay": 10 },
          279  +                    dInfo: {}
          280  +                });
          281  +                this.stopWaitIcon();
          282  +                break;
          283  +            default:
          284  +                console.log("Action inconnue: ", sAction);
          285  +        }
   259    286       }
   260    287   
   261    288       openURL (sURL) {
   262    289           xGrammalectePort.postMessage({
   263    290               sCommand: "openURL",
   264    291               dParam: {"sURL": sURL},
   265    292               dInfo: {}
   266    293           });
   267    294       }
   268    295   }

Changes to gc_lang/fr/webext/content_scripts/panel_gc.js.

    58     58           this.xGCPanelContent.appendChild(this.xParagraphList);
    59     59           this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false);
    60     60           this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent);
    61     61           this.xPanelContent.appendChild(this.xGCPanelContent);
    62     62           this.xNode = null;
    63     63           this.oTextControl = new GrammalecteTextControl();
    64     64           this.bAutoRefresh = false;
           65  +        this.nLastResult = 0
    65     66           // Lexicographer
    66     67           this.nLxgCount = 0;
    67     68           this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"});
    68     69           this.xPanelContent.appendChild(this.xLxgPanelContent);
    69     70           // Conjugueur
    70     71           this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"});
    71     72           this.xConjPanelContent.innerHTML = sGrammalecteConjugueurHTML;  // @Reviewers: sGrammalecteConjugueurHTML is a const value defined in <content_scripts/html_src.js>
................................................................................
   135    136       }
   136    137   
   137    138       start (what) {
   138    139           this.oTooltip.hide();
   139    140           this.bWorking = false;
   140    141           this.clear();
   141    142           this.hideMessage();
          143  +        this.resetTimer();
   142    144           if (typeof(what) === "string") {
   143    145               // text
   144    146               this.xNode = null;
   145    147               this.oTextControl.setText(what);
   146    148           } else if (what.nodeType && what.nodeType === 1) {
   147    149               // node
   148    150               this.xNode = what;
................................................................................
   155    157       }
   156    158   
   157    159       recheckAll () {
   158    160           this.oTooltip.hide();
   159    161           this.showEditor();
   160    162           this.clear();
   161    163           this.startWaitIcon();
          164  +        this.resetTimer();
   162    165           xGrammalectePort.postMessage({
   163    166               sCommand: "parseAndSpellcheck",
   164    167               dParam: {sText: this.oTextControl.getText(), sCountry: "FR", bDebug: false, bContext: false},
   165    168               dInfo: ((this.xNode) ? {sTextAreaId: this.xNode.id} : {})
   166    169           });
   167    170       }
   168    171   
................................................................................
   216    219           oGrammalecte.clearRightClickedNode();
   217    220           this.xPanel.style.display = "none";
   218    221           this.oTextControl.clear();
   219    222       }
   220    223   
   221    224       addParagraphResult (oResult) {
   222    225           try {
          226  +            this.resetTimer();
   223    227               if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) {
   224    228                   let xNodeDiv = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_block"});
   225    229                   // actions
   226    230                   let xActionsBar = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_actions"});
   227    231                   xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum}));
   228    232                   xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"}));
   229    233                   // paragraph
................................................................................
   262    266                   this.xParagraphList.appendChild(xNodeDiv);
   263    267               }
   264    268           }
   265    269           catch (e) {
   266    270               showError(e);
   267    271           }
   268    272       }
          273  +
          274  +    resetTimer () {
          275  +        this.nLastResult = Date.now();
          276  +        window.clearTimeout(this.nTimer);
          277  +        this.nTimer = window.setTimeout(
          278  +            oGrammalecte.oGCPanel.showMessage.bind(this),
          279  +            5000,
          280  +            "Le serveur grammatical semble ne plus répondre.",
          281  +            "Arrêter et relancer le serveur grammatical.",
          282  +            "restartWorker"
          283  +        );
          284  +    }
          285  +
          286  +    endTimer () {
          287  +        window.clearTimeout(this.nTimer);
          288  +    }
   269    289   
   270    290       recheckParagraph (iParaNum) {
   271    291           let sParagraphId = "grammalecte_paragraph" + iParaNum;
   272    292           let xParagraph = this.xParent.getElementById(sParagraphId);
   273    293           this.blockParagraph(xParagraph);
   274    294           let sText = this.purgeText(xParagraph.textContent);
   275    295           xGrammalectePort.postMessage({

Changes to gc_lang/fr/webext/panel/main.html.

   153    153             </div>
   154    154           </section> <!-- #sc_options_page -->
   155    155   
   156    156           <section id="test_page" class="page">
   157    157             <div id="test_cmd">
   158    158               <h1>ZONE DE TEST</h1>
   159    159               <p>Section de contrôle pour le développement du logiciel…</p>
          160  +            <div id="restart_worker" class="button blue fright">Redémarrer le worker</div>
   160    161               <p id="link_testpage" class="link" data-url="https://grammalecte.net/test.html">Page de test</p>
   161    162               <textarea id="text_to_test" rows="10"></textarea>
   162    163               <div id="fulltests_button" class="button blue">Tests complets</div> <div id="text_to_test_button" class="button green fright">Analyser</div>
   163    164             </div>
   164    165             <pre id="tests_result"></pre>
   165    166           </section> <!-- #test_page -->
   166    167   

Changes to gc_lang/fr/webext/panel/main.js.

    94     94               }
    95     95               else if (xElem.id == "dic_personal_button") {
    96     96                   browser.runtime.sendMessage({
    97     97                       sCommand: "openLexiconEditor",
    98     98                       dParam: { "dictionary": "__personal__"},
    99     99                       dInfo: {}
   100    100                   });
          101  +            }
          102  +            else if (xElem.id == "restart_worker") {
          103  +                browser.runtime.sendMessage({
          104  +                    sCommand: "restartWorker",
          105  +                    dParam: { "nDelayLimit": 3 },
          106  +                    dInfo: {}
          107  +                });
   101    108               }
   102    109           } else if (xElem.className.startsWith("select")) {
   103    110               showPage(xElem.dataset.page);
   104    111           }/* else if (xElem.tagName === "A") {
   105    112               openURL(xElem.getAttribute("href"));
   106    113           }*/
   107    114       },