diff options
author | Ven <vendicated@riseup.net> | 2022-12-25 20:47:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-25 20:47:35 +0100 |
commit | 2e5d27b6b63097e96e25819df7a8cdd667c521b3 (patch) | |
tree | 082b0f1c7cb0210d208c7cb8017e9da97b3b4196 /src/preload.ts | |
parent | 2172cae779fb24f9bcc8c54a0b6538da0b52bafd (diff) | |
download | Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.tar.gz Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.tar.bz2 Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.zip |
feat: Proper CSS api & css bundle (#269)
Co-authored-by: Vap0r1ze <superdash993@gmail.com>
Diffstat (limited to 'src/preload.ts')
-rw-r--r-- | src/preload.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/preload.ts b/src/preload.ts index dcf2554..7460081 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -44,6 +44,34 @@ contextBridge.exposeInMainWorld("VencordNative", VencordNative); if (location.protocol !== "data:") { // Discord webFrame.executeJavaScript(readFileSync(join(__dirname, "renderer.js"), "utf-8")); + const rendererCss = join(__dirname, "renderer.css"); + + function insertCss(css: string) { + const style = document.createElement("style"); + style.id = "vencord-css-core"; + style.textContent = css; + + if (document.readyState === "complete") { + document.documentElement.appendChild(style); + } else { + document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild(style), { + once: true + }); + } + } + + try { + const css = readFileSync(rendererCss, "utf-8"); + insertCss(css); + } catch (err) { + if ((err as NodeJS.ErrnoException)?.code !== "ENOENT") + throw err; + + // hack: the pre update updater does not download this file, so manually download it + // TODO: remove this in a future version + ipcRenderer.invoke(IpcEvents.DOWNLOAD_VENCORD_CSS) + .then(insertCss); + } require(process.env.DISCORD_PRELOAD!); } else { // Monaco Popout |