From 36d4e901139669e6f47fbf8294e8c3a587ca5104 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 3 Apr 2023 05:19:46 +0200 Subject: [PATCH] migrate from browser bundle to Vencord:#765 --- src/main/index.ts | 3 +++ src/main/ipc.ts | 7 ------- src/main/mainWindow.ts | 2 +- src/main/vencord.ts | 22 ---------------------- src/preload/index.ts | 19 ++----------------- src/shared/IpcEvents.ts | 1 - src/shared/util.ts | 2 ++ 7 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 src/main/vencord.ts create mode 100644 src/shared/util.ts diff --git a/src/main/index.ts b/src/main/index.ts index 0b2f58d..8d150ef 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -2,8 +2,11 @@ import { app, BrowserWindow } from 'electron'; import { createMainWindow } from "./mainWindow"; import { createSplashWindow } from "./splash"; +import { join } from "path"; import "./ipc"; +require(join(__dirname, "Vencord/main.js")); + function createWindows() { const mainWindow = createMainWindow(); const splash = createSplashWindow(); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 2bb32ba..e69de29 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -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(); -}); diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 2a0df28..d8bf999 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -6,7 +6,7 @@ export function createMainWindow() { show: false, webPreferences: { nodeIntegration: false, - sandbox: true, + sandbox: false, contextIsolation: true, devTools: true, preload: join(__dirname, "preload.js") diff --git a/src/main/vencord.ts b/src/main/vencord.ts deleted file mode 100644 index 4a5672e..0000000 --- a/src/main/vencord.ts +++ /dev/null @@ -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; -} diff --git a/src/preload/index.ts b/src/preload/index.ts index 97dcbf6..1157456 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1,18 +1,3 @@ -import { ipcRenderer, webFrame } from "electron"; -import { GET_VENCORD } from "../shared/IpcEvents"; +import { join } from "path"; -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 - }); -} +require(join(__dirname, "Vencord/preload.js")); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index fc0ff82..e69de29 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -1 +0,0 @@ -export const GET_VENCORD = "VCDGetVencord"; diff --git a/src/shared/util.ts b/src/shared/util.ts new file mode 100644 index 0000000..139597f --- /dev/null +++ b/src/shared/util.ts @@ -0,0 +1,2 @@ + +