diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts
index ef3923ba..515ccc3f 100644
--- a/browser/VencordNativeStub.ts
+++ b/browser/VencordNativeStub.ts
@@ -16,51 +16,70 @@
* along with this program. If not, see .
*/
+///
+///
+
+import monacoHtml from "~fileContent/../src/components/monacoWin.html";
import * as DataStore from "../src/api/DataStore";
-import IpcEvents from "../src/utils/IpcEvents";
+import { debounce } from "../src/utils";
+import { getTheme, Theme } from "../src/utils/discord";
// Discord deletes this so need to store in variable
const { localStorage } = window;
// listeners for ipc.on
-const listeners = {} as Record>;
+const cssListeners = new Set<(css: string) => void>();
+const NOOP = () => { };
+const NOOP_ASYNC = async () => { };
-const handlers = {
- [IpcEvents.GET_REPO]: () => "https://github.com/Vendicated/Vencord", // shrug
- [IpcEvents.GET_SETTINGS_DIR]: () => "LocalStorage",
-
- [IpcEvents.GET_QUICK_CSS]: () => DataStore.get("VencordQuickCss").then(s => s ?? ""),
- [IpcEvents.SET_QUICK_CSS]: (css: string) => {
- DataStore.set("VencordQuickCss", css);
- listeners[IpcEvents.QUICK_CSS_UPDATE]?.forEach(l => l(null, css));
- },
-
- [IpcEvents.GET_SETTINGS]: () => localStorage.getItem("VencordSettings") || "{}",
- [IpcEvents.SET_SETTINGS]: (s: string) => localStorage.setItem("VencordSettings", s),
-
- [IpcEvents.GET_UPDATES]: () => ({ ok: true, value: [] }),
-
- [IpcEvents.OPEN_EXTERNAL]: (url: string) => open(url, "_blank"),
-};
-
-function onEvent(event: string, ...args: any[]) {
- const handler = handlers[event];
- if (!handler) throw new Error(`Event ${event} not implemented.`);
- return handler(...args);
-}
+const setCssDebounced = debounce((css: string) => VencordNative.quickCss.set(css));
// probably should make this less cursed at some point
window.VencordNative = {
- getVersions: () => ({}),
- ipc: {
- send: (event: string, ...args: any[]) => void onEvent(event, ...args),
- sendSync: onEvent,
- on(event: string, listener: () => {}) {
- (listeners[event] ??= new Set()).add(listener);
- },
- off(event: string, listener: () => {}) {
- return listeners[event]?.delete(listener);
- },
- invoke: (event: string, ...args: any[]) => Promise.resolve(onEvent(event, ...args))
+ native: {
+ getVersions: () => ({}),
+ openExternal: async (url) => void open(url, "_blank")
},
+
+ updater: {
+ getRepo: async () => ({ ok: true, value: "https://github.com/Vendicated/Vencord" }),
+ getUpdates: async () => ({ ok: true, value: [] }),
+ update: async () => ({ ok: true, value: false }),
+ rebuild: async () => ({ ok: true, value: true }),
+ },
+
+ quickCss: {
+ get: () => DataStore.get("VencordQuickCss").then(s => s ?? ""),
+ set: async (css: string) => {
+ await DataStore.set("VencordQuickCss", css);
+ cssListeners.forEach(l => l(css));
+ },
+ addChangeListener(cb) {
+ cssListeners.add(cb);
+ },
+ openFile: NOOP_ASYNC,
+ async openEditor() {
+ const features = `popup,width=${Math.min(window.innerWidth, 1000)},height=${Math.min(window.innerHeight, 1000)}`;
+ const win = open("about:blank", "VencordQuickCss", features);
+ if (!win) {
+ alert("Failed to open QuickCSS popup. Make sure to allow popups!");
+ return;
+ }
+
+ win.setCss = setCssDebounced;
+ win.getCurrentCss = () => VencordNative.quickCss.get();
+ win.getTheme = () =>
+ getTheme() === Theme.Light
+ ? "vs-light"
+ : "vs-dark";
+
+ win.document.write(monacoHtml);
+ },
+ },
+
+ settings: {
+ get: () => localStorage.getItem("VencordSettings") || "{}",
+ set: async (s: string) => localStorage.setItem("VencordSettings", s),
+ getSettingsDir: async () => "LocalStorage"
+ }
};
diff --git a/src/Vencord.ts b/src/Vencord.ts
index ad793456..4c0d2a86 100644
--- a/src/Vencord.ts
+++ b/src/Vencord.ts
@@ -33,7 +33,7 @@ import { patches, PMLogger, startAllPlugins } from "./plugins";
import { localStorage } from "./utils/localStorage";
import { relaunch } from "./utils/native";
import { getCloudSettings, putCloudSettings } from "./utils/settingsSync";
-import { checkForUpdates, rebuild, update, UpdateLogger } from "./utils/updater";
+import { checkForUpdates, update,UpdateLogger } from "./utils/updater";
import { onceReady } from "./webpack";
import { SettingsRouter } from "./webpack/common";
@@ -76,7 +76,6 @@ async function init() {
if (Settings.autoUpdate) {
await update();
- await rebuild();
if (Settings.autoUpdateNotification)
setTimeout(() => showNotification({
title: "Vencord has been updated!",
diff --git a/src/VencordNative.ts b/src/VencordNative.ts
index 3cd53e18..02de74f6 100644
--- a/src/VencordNative.ts
+++ b/src/VencordNative.ts
@@ -16,34 +16,46 @@
* along with this program. If not, see .
*/
-import IPC_EVENTS from "@utils/IpcEvents";
-import { IpcRenderer, ipcRenderer } from "electron";
+import { IpcEvents } from "@utils/IpcEvents";
+import { IpcRes } from "@utils/types";
+import { ipcRenderer } from "electron";
-function assertEventAllowed(event: string) {
- if (!(event in IPC_EVENTS)) throw new Error(`Event ${event} not allowed.`);
+function invoke(event: IpcEvents, ...args: any[]) {
+ return ipcRenderer.invoke(event, ...args) as Promise;
}
+
+export function sendSync(event: IpcEvents, ...args: any[]) {
+ return ipcRenderer.sendSync(event, ...args) as T;
+}
+
export default {
- getVersions: () => process.versions,
- ipc: {
- send(event: string, ...args: any[]) {
- assertEventAllowed(event);
- ipcRenderer.send(event, ...args);
+ updater: {
+ getUpdates: () => invoke[]>>(IpcEvents.GET_UPDATES),
+ update: () => invoke>(IpcEvents.UPDATE),
+ rebuild: () => invoke>(IpcEvents.BUILD),
+ getRepo: () => invoke>(IpcEvents.GET_REPO),
+ },
+
+ settings: {
+ get: () => sendSync(IpcEvents.GET_SETTINGS),
+ set: (settings: string) => invoke(IpcEvents.SET_SETTINGS, settings),
+ getSettingsDir: () => invoke(IpcEvents.GET_SETTINGS_DIR),
+ },
+
+ quickCss: {
+ get: () => invoke(IpcEvents.GET_QUICK_CSS),
+ set: (css: string) => invoke(IpcEvents.SET_QUICK_CSS, css),
+
+ addChangeListener(cb: (newCss: string) => void) {
+ ipcRenderer.on(IpcEvents.QUICK_CSS_UPDATE, (_, css) => cb(css));
},
- sendSync(event: string, ...args: any[]): T {
- assertEventAllowed(event);
- return ipcRenderer.sendSync(event, ...args);
- },
- on(event: string, listener: Parameters[1]) {
- assertEventAllowed(event);
- ipcRenderer.on(event, listener);
- },
- off(event: string, listener: Parameters[1]) {
- assertEventAllowed(event);
- ipcRenderer.off(event, listener);
- },
- invoke(event: string, ...args: any[]): Promise {
- assertEventAllowed(event);
- return ipcRenderer.invoke(event, ...args);
- }
- }
+
+ openFile: () => invoke(IpcEvents.OPEN_QUICKCSS),
+ openEditor: () => invoke(IpcEvents.OPEN_MONACO_EDITOR),
+ },
+
+ native: {
+ getVersions: () => process.versions as Partial,
+ openExternal: (url: string) => invoke(IpcEvents.OPEN_EXTERNAL, url)
+ },
};
diff --git a/src/api/settings.ts b/src/api/settings.ts
index 35381d88..2329f945 100644
--- a/src/api/settings.ts
+++ b/src/api/settings.ts
@@ -17,7 +17,6 @@
*/
import { debounce } from "@utils/debounce";
-import IpcEvents from "@utils/IpcEvents";
import { localStorage } from "@utils/localStorage";
import Logger from "@utils/Logger";
import { mergeDefaults } from "@utils/misc";
@@ -94,7 +93,7 @@ const DefaultSettings: Settings = {
};
try {
- var settings = JSON.parse(VencordNative.ipc.sendSync(IpcEvents.GET_SETTINGS)) as Settings;
+ var settings = JSON.parse(VencordNative.settings.get()) as Settings;
mergeDefaults(settings, DefaultSettings);
} catch (err) {
var settings = mergeDefaults({} as Settings, DefaultSettings);
@@ -173,7 +172,7 @@ function makeProxy(settings: any, root = settings, path = ""): Settings {
PlainSettings.cloud.settingsSyncVersion = Date.now();
localStorage.Vencord_settingsDirty = true;
saveSettingsOnFrequentAction();
- VencordNative.ipc.invoke(IpcEvents.SET_SETTINGS, JSON.stringify(root, null, 4));
+ VencordNative.settings.set(JSON.stringify(root, null, 4));
return true;
}
});
@@ -249,10 +248,7 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) {
logger.info(`Migrating settings from old name ${oldName} to ${name}`);
plugins[name] = plugins[oldName];
delete plugins[oldName];
- VencordNative.ipc.invoke(
- IpcEvents.SET_SETTINGS,
- JSON.stringify(settings, null, 4)
- );
+ VencordNative.settings.set(JSON.stringify(settings, null, 4));
break;
}
}
diff --git a/src/components/DonateButton.tsx b/src/components/DonateButton.tsx
index 49f079b4..c027fcf2 100644
--- a/src/components/DonateButton.tsx
+++ b/src/components/DonateButton.tsx
@@ -16,7 +16,6 @@
* along with this program. If not, see .
*/
-import IpcEvents from "@utils/IpcEvents";
import { Button } from "@webpack/common";
import { Heart } from "./Heart";
@@ -27,9 +26,7 @@ export default function DonateButton(props: any) {
{...props}
look={Button.Looks.LINK}
color={Button.Colors.TRANSPARENT}
- onClick={() =>
- VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated")
- }
+ onClick={() => VencordNative.native.openExternal("https://github.com/sponsors/Vendicated")}
>
Donate
diff --git a/src/components/Monaco.ts b/src/components/Monaco.ts
deleted file mode 100644
index 59ed7bbb..00000000
--- a/src/components/Monaco.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Vencord, a modification for Discord's desktop app
- * Copyright (c) 2022 Vendicated and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-import { debounce } from "@utils/debounce";
-import IpcEvents from "@utils/IpcEvents";
-import { Queue } from "@utils/Queue";
-import { find } from "@webpack";
-
-import monacoHtml from "~fileContent/monacoWin.html";
-
-const queue = new Queue();
-const setCss = debounce((css: string) => {
- queue.push(() => VencordNative.ipc.invoke(IpcEvents.SET_QUICK_CSS, css));
-});
-
-export async function launchMonacoEditor() {
- const features = `popup,width=${Math.min(window.innerWidth, 1000)},height=${Math.min(window.innerHeight, 1000)}`;
- const win = open("about:blank", "VencordQuickCss", features);
- if (!win) {
- alert("Failed to open QuickCSS popup. Make sure to allow popups!");
- return;
- }
-
- win.setCss = setCss;
- win.getCurrentCss = () => VencordNative.ipc.invoke(IpcEvents.GET_QUICK_CSS);
- win.getTheme = () =>
- find(m =>
- m.ProtoClass?.typeName.endsWith("PreloadedUserSettings")
- )?.getCurrentValue()?.appearance?.theme === 2
- ? "vs-light"
- : "vs-dark";
-
- win.document.write(monacoHtml);
-
- window.__VENCORD_MONACO_WIN__ = new WeakRef(win);
-}
diff --git a/src/components/VencordSettings/Updater.tsx b/src/components/VencordSettings/Updater.tsx
index 6dffbc87..fb783943 100644
--- a/src/components/VencordSettings/Updater.tsx
+++ b/src/components/VencordSettings/Updater.tsx
@@ -25,7 +25,7 @@ import { Link } from "@components/Link";
import { Margins } from "@utils/margins";
import { classes, useAwaiter } from "@utils/misc";
import { relaunch } from "@utils/native";
-import { changes, checkForUpdates, getRepo, isNewer, rebuild, update, updateError, UpdateLogger } from "@utils/updater";
+import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater";
import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common";
import gitHash from "~git-hash";
@@ -125,7 +125,6 @@ function Updatable(props: CommonProps) {
onClick={withDispatcher(setIsUpdating, async () => {
if (await update()) {
setUpdates([]);
- await rebuild();
await new Promise(r => {
Alerts.show({
title: "Update Success!",
diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx
index 75122085..672e04ee 100644
--- a/src/components/VencordSettings/VencordTab.tsx
+++ b/src/components/VencordSettings/VencordTab.tsx
@@ -23,7 +23,6 @@ import { classNameFactory } from "@api/Styles";
import DonateButton from "@components/DonateButton";
import ErrorBoundary from "@components/ErrorBoundary";
import { ErrorCard } from "@components/ErrorCard";
-import IpcEvents from "@utils/IpcEvents";
import { Margins } from "@utils/margins";
import { identity, useAwaiter } from "@utils/misc";
import { relaunch, showItemInFolder } from "@utils/native";
@@ -39,7 +38,7 @@ type KeysOfType