aboutsummaryrefslogtreecommitdiff
path: root/src/preload.ts
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-04-09 04:04:02 +0200
committerGitHub <noreply@github.com>2023-04-09 04:04:02 +0200
commit08822dd19064ea5b707117c5ed51f62dd0a8e316 (patch)
tree1020c2dad28f5dc502f797ca09066145fcc12109 /src/preload.ts
parentbfa20f2634a0f3f73a03135f9ddb9d0dfe566e88 (diff)
downloadVencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.tar.gz
Vencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.tar.bz2
Vencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.zip
Improvements for VencordDesktop (#847)
Diffstat (limited to 'src/preload.ts')
-rw-r--r--src/preload.ts35
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