Equicord/src/preload.ts

42 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-10-22 01:17:06 +02:00
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { debounce } from "@shared/debounce";
import { IpcEvents } from "@shared/IpcEvents";
import { contextBridge, webFrame } from "electron/renderer";
2022-10-22 18:18:41 +02:00
import VencordNative, { invoke, sendSync } from "./VencordNative";
2022-08-29 18:11:44 +02:00
contextBridge.exposeInMainWorld("VencordNative", VencordNative);
2022-08-29 02:25:27 +02:00
2023-04-09 04:04:02 +02:00
// Discord
2022-10-22 04:41:33 +02:00
if (location.protocol !== "data:") {
invoke(IpcEvents.INIT_FILE_WATCHERS);
if (IS_DISCORD_DESKTOP) {
webFrame.executeJavaScript(sendSync<string>(IpcEvents.PRELOAD_GET_RENDERER_JS));
// Not supported in sandboxed preload scripts but Discord doesn't support it either so who cares
require(process.env.DISCORD_PRELOAD!);
2023-04-09 04:04:02 +02:00
}
} // Monaco popout
else {
contextBridge.exposeInMainWorld("setCss", debounce(VencordNative.quickCss.set));
contextBridge.exposeInMainWorld("getCurrentCss", VencordNative.quickCss.get);
contextBridge.exposeInMainWorld("getTheme", VencordNative.quickCss.getEditorTheme);
2022-10-22 04:41:33 +02:00
}