~glacambre/firenvim

ref: 076c1a4f04db2173afb395d0af8c63a5bbcab6a8 firenvim/src/browserAction.ts -rw-r--r-- 1.6 KiB
076c1a4f — Brian Ryall fixes installing fire nvim on brave 11 months ago
                                                                                
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
function displayMessages(func: "getError" | "getWarning", id: "errors" | "warnings") {
    function insertMessage(msg: any) {
        document.getElementById(id).innerText = msg;
    }
    return browser.runtime.sendMessage({ funcName: [func] })
        .then(insertMessage)
        .catch(insertMessage);
}

function displayErrorsAndWarnings() {
    return Promise.all([displayMessages("getWarning", "warnings"), displayMessages("getError", "errors")]);
}

async function updateDisableButton() {
    const tabId = (await browser.runtime.sendMessage({
        args: {
            args: [{ active: true, currentWindow: true }],
            funcName: [ "browser", "tabs", "query" ],
        },
        funcName: ["exec"],
    }))[0].id;
    const disabled = (await browser.runtime.sendMessage({
        args: [tabId, "disabled"],
        funcName: ["getTabValueFor"],
    }));
    const button = document.getElementById("disableFirenvim");
    if (disabled === "true") {
        button.innerText = "Enable in this tab";
    } else {
        button.innerText = "Disable in this tab";
    }
}

addEventListener("DOMContentLoaded", () => {
    document.getElementById("reloadSettings").addEventListener("click", () => {
        browser.runtime.sendMessage( { funcName: ["updateSettings"] })
            .then(displayErrorsAndWarnings)
            .catch(displayErrorsAndWarnings);
    });
    document.getElementById("disableFirenvim").addEventListener("click", () => {
        browser.runtime.sendMessage( { funcName: ["toggleDisabled"] })
            .then(updateDisableButton);
    });
    displayErrorsAndWarnings();
    updateDisableButton();
});