diff options
Diffstat (limited to 'src/preload.ts')
-rw-r--r-- | src/preload.ts | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/preload.ts b/src/preload.ts index b75574a..276cceb 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -26,27 +26,23 @@ import VencordNative from "./VencordNative"; contextBridge.exposeInMainWorld("VencordNative", VencordNative); +// Discord if (location.protocol !== "data:") { - // Discord - webFrame.executeJavaScript(readFileSync(join(__dirname, "renderer.js"), "utf-8")); + // #region cssInsert const rendererCss = join(__dirname, "renderer.css"); - function insertCss(css: string) { - const style = document.createElement("style"); - style.id = "vencord-css-core"; - style.textContent = css; + const style = document.createElement("style"); + style.id = "vencord-css-core"; + style.textContent = readFileSync(rendererCss, "utf-8"); - if (document.readyState === "complete") { - document.documentElement.appendChild(style); - } else { - document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild(style), { - once: true - }); - } + if (document.readyState === "complete") { + document.documentElement.appendChild(style); + } else { + document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild(style), { + once: true + }); } - const css = readFileSync(rendererCss, "utf-8"); - insertCss(css); if (IS_DEV) { // persistent means keep process running if watcher is the only thing still running // which we obviously don't want @@ -54,11 +50,14 @@ if (location.protocol !== "data:") { document.getElementById("vencord-css-core")!.textContent = readFileSync(rendererCss, "utf-8"); }); } + // #endregion - if (process.env.DISCORD_PRELOAD) + if (process.env.DISCORD_PRELOAD) { + webFrame.executeJavaScript(readFileSync(join(__dirname, "renderer.js"), "utf-8")); require(process.env.DISCORD_PRELOAD); -} else { - // Monaco Popout + } +} // Monaco popout +else { contextBridge.exposeInMainWorld("setCss", debounce(s => VencordNative.ipc.invoke(IpcEvents.SET_QUICK_CSS, s))); contextBridge.exposeInMainWorld("getCurrentCss", () => VencordNative.ipc.invoke(IpcEvents.GET_QUICK_CSS)); // shrug |