fixes
This commit is contained in:
parent
805b6fbcc4
commit
e265e70fb9
6 changed files with 40 additions and 6 deletions
|
@ -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"
|
||||||
},
|
},
|
||||||
|
|
|
@ -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", ["."]);
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in a new issue