haitop/src/preload/index.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-04-09 22:49:50 +02:00
/*
* SPDX-License-Identifier: GPL-3.0
2023-07-13 19:03:13 +02:00
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
2023-04-09 22:49:50 +02:00
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { contextBridge, ipcRenderer, webFrame } from "electron";
2023-04-09 03:06:19 +02:00
import { readFileSync, watch } from "fs";
2023-04-09 22:49:50 +02:00
2023-04-09 01:22:31 +02:00
import { IpcEvents } from "../shared/IpcEvents";
2023-07-13 19:03:13 +02:00
import { VesktopNative } from "./VesktopNative";
2023-04-04 01:35:37 +02:00
2023-07-13 19:03:13 +02:00
contextBridge.exposeInMainWorld("VesktopNative", VesktopNative);
// TODO: remove legacy alias once main Vencord codebase has migrated and some time has passed
contextBridge.exposeInMainWorld("VencordDesktopNative", VesktopNative);
2023-03-31 01:21:06 +02:00
2023-04-09 01:22:31 +02:00
require(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_FILE));
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT));
2023-04-09 01:22:31 +02:00
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT));
2023-04-09 03:06:19 +02: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 04:05:56 +02:00
2023-07-13 19:03:13 +02:00
VesktopNative.spellcheck.setLanguages(window.navigator.languages);