This commit is contained in:
Vendicated 2023-04-09 03:06:19 +02:00
parent 805b6fbcc4
commit e265e70fb9
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
6 changed files with 40 additions and 6 deletions

View file

@ -14,6 +14,7 @@
"package:dir": "pnpm build && electron-builder --dir", "package:dir": "pnpm build && electron-builder --dir",
"start": "pnpm build && electron .", "start": "pnpm build && electron .",
"start:dev": "pnpm build --dev && electron .", "start:dev": "pnpm build --dev && electron .",
"start:watch": "tsx scripts/startWatch.mts",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"watch": "pnpm build --watch" "watch": "pnpm build --watch"
}, },

View file

@ -11,5 +11,5 @@ function spawn(bin: string, args: string[]) {
cpSpawn(join("node_modules", ".bin", bin + EXT), args, OPTS); cpSpawn(join("node_modules", ".bin", bin + EXT), args, OPTS);
} }
spawn("tsx", ["scripts/build/build.mts", "--", "--watch"]); spawn("tsx", ["scripts/build/build.mts", "--", "--watch", "--dev"]);
spawn("electron", ["."]); spawn("electron", ["."]);

View file

@ -20,12 +20,18 @@ ipcMain.on(IpcEvents.GET_RENDERER_SCRIPT, e => {
e.returnValue = readFileSync(join(__dirname, "renderer.js"), "utf-8"); e.returnValue = readFileSync(join(__dirname, "renderer.js"), "utf-8");
}); });
ipcMain.handle(IpcEvents.GET_RENDERER_STYLES, () => readFile(join(__dirname, "renderer.css"), "utf-8")); ipcMain.on(IpcEvents.GET_RENDERER_CSS_FILE, e => {
e.returnValue = join(__dirname, "renderer.css");
});
ipcMain.on(IpcEvents.GET_SETTINGS, e => { ipcMain.on(IpcEvents.GET_SETTINGS, e => {
e.returnValue = PlainSettings; e.returnValue = PlainSettings;
}); });
ipcMain.on(IpcEvents.GET_VERSION, e => {
e.returnValue = app.getVersion();
});
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, settings) => { ipcMain.handle(IpcEvents.SET_SETTINGS, (_, settings) => {
setSettings(settings); setSettings(settings);
}); });

View file

@ -1,4 +1,4 @@
import { app, ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import type { Settings } from "shared/settings"; import type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest"; import type { LiteralUnion } from "type-fest";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
@ -14,7 +14,7 @@ function sendSync<T = any>(event: IpcEvents, ...args: any[]) {
export const VencordDesktopNative = { export const VencordDesktopNative = {
app: { app: {
relaunch: () => invoke<void>(IpcEvents.RELAUNCH), relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
getVersion: () => app.getVersion() getVersion: () => sendSync<void>(IpcEvents.GET_VERSION)
}, },
fileManager: { fileManager: {
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path), showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),

View file

@ -1,4 +1,5 @@
import { contextBridge, ipcRenderer, webFrame } from "electron"; import { contextBridge, ipcRenderer, webFrame } from "electron";
import { readFileSync, watch } from "fs";
import { IpcEvents } from "../shared/IpcEvents"; import { IpcEvents } from "../shared/IpcEvents";
import { VencordDesktopNative } from "./VencordDesktopNative"; import { VencordDesktopNative } from "./VencordDesktopNative";
@ -8,4 +9,28 @@ require(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_FILE));
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT)); webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT));
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT)); webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT));
ipcRenderer.invoke(IpcEvents.GET_RENDERER_STYLES).then(s => webFrame.insertCSS(s));
// #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

View file

@ -2,11 +2,13 @@ export const enum IpcEvents {
GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE", GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE",
GET_VENCORD_RENDERER_SCRIPT = "VCD_GET_VC_RENDERER_SCRIPT", GET_VENCORD_RENDERER_SCRIPT = "VCD_GET_VC_RENDERER_SCRIPT",
GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT", GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT",
GET_RENDERER_STYLES = "VCD_GET_RENDERER_STYLES", GET_RENDERER_CSS_FILE = "VCD_GET_RENDERER_CSS_FILE",
RELAUNCH = "VCD_RELAUNCH", RELAUNCH = "VCD_RELAUNCH",
FOCUS = "VCD_FOCUS", FOCUS = "VCD_FOCUS",
GET_VERSION = "VCD_GET_VERSION",
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER", SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER",
GET_SETTINGS = "VCD_GET_SETTINGS", GET_SETTINGS = "VCD_GET_SETTINGS",
SET_SETTINGS = "VCD_SET_SETTINGS", SET_SETTINGS = "VCD_SET_SETTINGS",