JS API discussion

This is what my code was like before the async update in the AnkiDroid JS API. The change did require adding a bunch more code so I guess I would like the desktop addon to also follow the same async structure as that’d remove the need for the handlePromise helper.

    const setReps = (repsVal) => {
        setInfoInSpan("reps", "reps: " + repsNum);
    };
    const setFactor = (fctVal) => {
        setInfoInSpan("ease", "ease: " + fctNum / 10 + "%");
    };
    const setIvl = (ivlVal) => {
        setInfoInSpan("ivl", "ivl: " + ivlNum + "d");
    };
    try {
        const jsApiContract = { version: "0.0.3", developer: "https://github.com/jhhr" };

        const api = new AnkiDroidJS(jsApiContract);

        console.log("AnkiDroid API", api);

        setReps(api.ankiGetCardReps());
        setFactor(api.ankiGetCardFactor());
        setIvl(api.ankiGetCardInterval());
    } catch (e) {
        if (globalThis.ankiPlatform !== "desktop") {
            console.log("AnkiDroid API error", e);
        } else {
            pycmd("AnkiJS.ankiGetCardReps()", setReps);
            pycmd("AnkiJS.ankiGetCardFactor()", setFactor);
            pycmd("AnkiJS.ankiGetCardInterval()", setIvl);
        }
    }

But what I’d most like is that all the functions available in the AnkiDroid JS API would also be implemented in the addon. I’m not going to implement anything in my cards where the implementation would have to vastly different on desktop vs Android so I’m basically limited to the intersection set of the JS API addon and the AnkiDroid JS API.

I’ve been thinking a little about doing (some of) that work but have only done the one function that’s in my fork so far. Maybe we can work together on, split the work?