Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.7 KB
Raw Blame
(() => {
    if (location.pathname.endsWith("/boot.html") && !new URLSearchParams(location.search).has("remote")) {
        return;
    }
    const {ipcRenderer} = require("electron");
    const fs = require("node:fs");
    const path = require("node:path");
    const button = document.createElement("button");
    button.type = "button";
    button.className = "b3-button";
    const langSelect = document.querySelector(".lang");
    const language = () => langSelect?.value || new URLSearchParams(location.search).get("lang") || "en";
    const update = () => {
        let lang = language();
        if (!/^[a-z]{2}(?:-[A-Z]{2})?$/.test(lang)) {
            lang = "en";
        }
        try {
            button.textContent = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "appearance", "langs", lang + ".json"),
                "utf8")).connectRemoteKernel;
        } catch (error) {
            button.textContent = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "appearance", "langs", "en.json"),
                "utf8")).connectRemoteKernel;
        }
    };
    button.addEventListener("click", () => ipcRenderer.send("siyuan-manage-connections", {lang: language()}));
    langSelect?.addEventListener("change", update);
    update();
    const crashActions = new URLSearchParams(location.search).get("crash") === "1" ?
        document.querySelector(".crash-actions") : null;
    if (crashActions) {
        button.classList.add("b3-button--outline");
        crashActions.append(button);
    } else {
        button.style.cssText = "position:fixed;bottom:16px;right:16px;z-index:1000;-webkit-app-region:no-drag;width:auto";
        document.body.append(button);
    }
})();