2023-04-09 20:49:50 +00:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
|
|
|
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
|
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
*/
|
|
|
|
|
2023-04-04 02:40:03 +00:00
|
|
|
import { contextBridge, ipcRenderer, webFrame } from "electron";
|
2023-04-09 01:06:19 +00:00
|
|
|
import { readFileSync, watch } from "fs";
|
2023-04-09 20:49:50 +00:00
|
|
|
|
2023-04-08 23:22:31 +00:00
|
|
|
import { IpcEvents } from "../shared/IpcEvents";
|
2023-04-08 23:20:00 +00:00
|
|
|
import { VencordDesktopNative } from "./VencordDesktopNative";
|
2023-04-03 23:35:37 +00:00
|
|
|
|
2023-04-08 23:20:00 +00:00
|
|
|
contextBridge.exposeInMainWorld("VencordDesktopNative", VencordDesktopNative);
|
2023-03-30 23:21:06 +00:00
|
|
|
|
2023-04-08 23:22:31 +00:00
|
|
|
require(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_FILE));
|
2023-04-04 02:40:03 +00:00
|
|
|
|
2023-04-09 00:26:31 +00:00
|
|
|
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT));
|
2023-04-08 23:22:31 +00:00
|
|
|
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT));
|
2023-04-09 01:06:19 +00:00
|
|
|
|
|
|
|
// #region css
|
|
|
|
const rendererCss = ipcRenderer.sendSync(IpcEvents.GET_RENDERER_CSS_FILE);
|
|
|
|
|
|
|
|
const style = document.createElement("style");
|
|
|
|
style.id = "vcd-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 (IS_DEV) {
|
|
|
|
// persistent means keep process running if watcher is the only thing still running
|
|
|
|
// which we obviously don't want
|
|
|
|
watch(rendererCss, { persistent: false }, () => {
|
|
|
|
document.getElementById("vcd-css-core")!.textContent = readFileSync(rendererCss, "utf-8");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// #endregion
|
2023-04-14 02:05:56 +00:00
|
|
|
|
|
|
|
VencordDesktopNative.spellcheck.setLanguages(window.navigator.languages);
|