migrate from browser bundle to Vencord:#765

This commit is contained in:
Vendicated 2023-04-03 05:19:46 +02:00
parent 4a9b882119
commit 36d4e90113
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
7 changed files with 8 additions and 48 deletions

View file

@ -2,8 +2,11 @@ import { app, BrowserWindow } from 'electron';
import { createMainWindow } from "./mainWindow"; import { createMainWindow } from "./mainWindow";
import { createSplashWindow } from "./splash"; import { createSplashWindow } from "./splash";
import { join } from "path";
import "./ipc"; import "./ipc";
require(join(__dirname, "Vencord/main.js"));
function createWindows() { function createWindows() {
const mainWindow = createMainWindow(); const mainWindow = createMainWindow();
const splash = createSplashWindow(); const splash = createSplashWindow();

View file

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

View file

@ -6,7 +6,7 @@ export function createMainWindow() {
show: false, show: false,
webPreferences: { webPreferences: {
nodeIntegration: false, nodeIntegration: false,
sandbox: true, sandbox: false,
contextIsolation: true, contextIsolation: true,
devTools: true, devTools: true,
preload: join(__dirname, "preload.js") preload: join(__dirname, "preload.js")

View file

@ -1,22 +0,0 @@
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,18 +1,3 @@
import { ipcRenderer, webFrame } from "electron"; import { join } from "path";
import { GET_VENCORD } from "../shared/IpcEvents";
const { js, css } = ipcRenderer.sendSync(GET_VENCORD); require(join(__dirname, "Vencord/preload.js"));
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
});
}

View file

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

2
src/shared/util.ts Normal file
View file

@ -0,0 +1,2 @@