Add basic Vencord injection

This commit is contained in:
Vendicated 2023-03-31 01:21:06 +02:00
parent 5d9eb3e4fb
commit ccaad66b1b
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
5 changed files with 50 additions and 1 deletions

View file

@ -2,6 +2,8 @@ import { app, BrowserWindow } from 'electron';
import { createMainWindow } from "./mainWindow";
import { createSplashWindow } from "./splash";
import "./ipc";
function createWindows() {
const mainWindow = createMainWindow();
const splash = createSplashWindow();

7
src/main/ipc.ts Normal file
View file

@ -0,0 +1,7 @@
import { ipcMain } from "electron";
import { GET_VENCORD } from "../shared/IpcEvents";
import { fetchVencord } from "./vencord";
ipcMain.on(GET_VENCORD, async e => {
e.returnValue = await fetchVencord();
});

22
src/main/vencord.ts Normal file
View file

@ -0,0 +1,22 @@
const BASE_URL = "https://github.com/Vendicated/Vencord/releases/download/devbuild/";
let VencordScripts: Record<"js" | "css", string>;
async function get(url: string) {
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to fetch ${url}: ${res.status} ${res.statusText}`);
return res.text();
}
export async function fetchVencord() {
if (!VencordScripts) {
const [js, css] = await Promise.all([
get(BASE_URL + "/browser.js"),
get(BASE_URL + "/browser.css")
]);
VencordScripts = { js, css };
}
return VencordScripts;
}

View file

@ -1 +1,18 @@
console.log("banana");
import { ipcRenderer, webFrame } from "electron";
import { GET_VENCORD } from "../shared/IpcEvents";
const { js, css } = ipcRenderer.sendSync(GET_VENCORD);
webFrame.executeJavaScript(js);
const style = document.createElement("style");
style.id = "vencord-css-core";
style.textContent = css;
if (document.readyState === "complete") {
document.documentElement.appendChild(style);
} else {
document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild(style), {
once: true
});
}

1
src/shared/IpcEvents.ts Normal file
View file

@ -0,0 +1 @@
export const GET_VENCORD = "VCDGetVencord";