aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-29 18:11:44 +0200
committerVendicated <vendicated@riseup.net>2022-08-29 18:11:44 +0200
commit876e622f4f61a4aa229ad69782d374335c3d8d6b (patch)
tree9119371f584f59b4512553d6548bd11fc84b7dcf /src
parentaf498e78291b67377aaf876c84143cdfe7c8b308 (diff)
downloadVencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.tar.gz
Vencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.tar.bz2
Vencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.zip
Progress
Diffstat (limited to 'src')
-rw-r--r--src/Vencord.ts4
-rw-r--r--src/VencordNative.ts11
-rw-r--r--src/globals.d.ts13
-rw-r--r--src/ipcMain.ts25
-rw-r--r--src/patcher.ts25
-rw-r--r--src/plugins.d.ts4
-rw-r--r--src/plugins/bar.ts3
-rw-r--r--src/plugins/foo.ts3
-rw-r--r--src/plugins/index.ts3
-rw-r--r--src/preload.ts8
-rw-r--r--src/utils/constants.ts3
-rw-r--r--src/utils/ipcEvents.ts3
-rw-r--r--src/utils/quickCss.ts6
13 files changed, 84 insertions, 27 deletions
diff --git a/src/Vencord.ts b/src/Vencord.ts
index 2a4a60a..449423c 100644
--- a/src/Vencord.ts
+++ b/src/Vencord.ts
@@ -1,3 +1,5 @@
import "./utils/patchWebpack";
+import "./utils/quickCss";
-export const Webpack = {}; \ No newline at end of file
+export const Webpack = {};
+import "./plugins";
diff --git a/src/VencordNative.ts b/src/VencordNative.ts
new file mode 100644
index 0000000..1798cbf
--- /dev/null
+++ b/src/VencordNative.ts
@@ -0,0 +1,11 @@
+import { IPC_QUICK_CSS_UPDATE, IPC_GET_QUICK_CSS } from './utils/ipcEvents';
+import { ipcRenderer } from 'electron';
+
+export default {
+ handleQuickCssUpdate(cb: (s: string) => void) {
+ ipcRenderer.on(IPC_QUICK_CSS_UPDATE, (_, css) => {
+ cb(css);
+ });
+ },
+ getQuickCss: () => ipcRenderer.invoke(IPC_GET_QUICK_CSS)
+}; \ No newline at end of file
diff --git a/src/globals.d.ts b/src/globals.d.ts
index 81b04af..610466a 100644
--- a/src/globals.d.ts
+++ b/src/globals.d.ts
@@ -1,9 +1,14 @@
-declare var appSettings: any;
+import TVencordNative from "./VencordNative";
declare global {
+ export var VencordNative: typeof TVencordNative;
+ export var appSettings: {
+ set(setting: string, v: any): void;
+ };
+
interface Window {
- webpackChunkdiscord_app: { push(chunk): any; };
+ webpackChunkdiscord_app: {
+ push(chunk: any): any;
+ };
}
}
-
-export { }; \ No newline at end of file
diff --git a/src/ipcMain.ts b/src/ipcMain.ts
new file mode 100644
index 0000000..c8fba37
--- /dev/null
+++ b/src/ipcMain.ts
@@ -0,0 +1,25 @@
+import { app, BrowserWindow, ipcMain } from "electron";
+import { fstat, watch } from "fs";
+import { open, readFile } from "fs/promises";
+import { join } from 'path';
+import { IPC_GET_SETTINGS_DIR, IPC_GET_QUICK_CSS, IPC_QUICK_CSS_UPDATE } from './utils/ipcEvents';
+
+const DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
+const SETTINGS_DIR = join(DATA_DIR, "settings");
+const QUICKCSS_PATH = join(SETTINGS_DIR, "quickCss.css");
+
+function readCss() {
+ return readFile(QUICKCSS_PATH, "utf-8").catch(() => "");
+}
+
+ipcMain.handle(IPC_GET_SETTINGS_DIR, () => SETTINGS_DIR);
+ipcMain.handle(IPC_GET_QUICK_CSS, () => readCss());
+
+export function initIpc(mainWindow: BrowserWindow) {
+ open(QUICKCSS_PATH, "a+").then(fd => {
+ fd.close();
+ watch(QUICKCSS_PATH, async () => {
+ mainWindow.webContents.postMessage(IPC_QUICK_CSS_UPDATE, await readCss());
+ });
+ });
+}
diff --git a/src/patcher.ts b/src/patcher.ts
index eb45b98..9fe3dd2 100644
--- a/src/patcher.ts
+++ b/src/patcher.ts
@@ -2,20 +2,21 @@
import electron, { app, BrowserWindowConstructorOptions } from "electron";
import installExt, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer";
import { join } from "path";
+import { initIpc } from './ipcMain';
console.log("[Vencord] Starting up...");
class BrowserWindow extends electron.BrowserWindow {
-
constructor(options: BrowserWindowConstructorOptions) {
if (options?.webPreferences?.preload && options.title) {
const original = options.webPreferences.preload;
options.webPreferences.preload = join(__dirname, "preload.js");
- process.env.APP_PATH = app.getAppPath();
process.env.DISCORD_PRELOAD = original;
- }
- super(options);
+
+ super(options);
+ initIpc(this);
+ } else super(options);
}
}
Object.assign(BrowserWindow, electron.BrowserWindow);
@@ -28,10 +29,11 @@ require.cache[electronPath]!.exports = {
BrowserWindow
};
-// Patch appSettingsa to force enable devtools
+// Patch appSettings to force enable devtools
Object.defineProperty(global, "appSettings", {
- set: (v) => {
+ set: (v: typeof global.appSettings) => {
v.set("DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING", true);
+ // @ts-ignore
delete global.appSettings;
global.appSettings = v;
},
@@ -41,20 +43,17 @@ Object.defineProperty(global, "appSettings", {
process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
electron.app.whenReady().then(() => {
- /* installExt(REACT_DEVELOPER_TOOLS)
+ installExt(REACT_DEVELOPER_TOOLS)
.then(() => console.log("Installed React DevTools"))
- .catch((err) => console.error("Failed to install React DevTools", err)); */
+ .catch((err) => console.error("Failed to install React DevTools", err));
// Remove CSP
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, cb) => {
- if (responseHeaders && url.endsWith(".css")) {
+ if (responseHeaders) {
delete responseHeaders["content-security-policy-report-only"];
delete responseHeaders["content-security-policy"];
- // probably makes github raw work? not tested.
- responseHeaders["content-type"] = ["text/css"];
- responseHeaders;
}
- cb({ cancel: false, responseHeaders: responseHeaders });
+ cb({ cancel: false, responseHeaders });
});
// Drop science and sentry requests
diff --git a/src/plugins.d.ts b/src/plugins.d.ts
new file mode 100644
index 0000000..e287823
--- /dev/null
+++ b/src/plugins.d.ts
@@ -0,0 +1,4 @@
+declare module "plugins" {
+ var plugins: Record<string, any>[];
+ export default plugins;
+} \ No newline at end of file
diff --git a/src/plugins/bar.ts b/src/plugins/bar.ts
new file mode 100644
index 0000000..d503e8a
--- /dev/null
+++ b/src/plugins/bar.ts
@@ -0,0 +1,3 @@
+export default {
+ name: "bar"
+}; \ No newline at end of file
diff --git a/src/plugins/foo.ts b/src/plugins/foo.ts
new file mode 100644
index 0000000..64c9323
--- /dev/null
+++ b/src/plugins/foo.ts
@@ -0,0 +1,3 @@
+export default {
+ name: "foo"
+}; \ No newline at end of file
diff --git a/src/plugins/index.ts b/src/plugins/index.ts
new file mode 100644
index 0000000..4e55edb
--- /dev/null
+++ b/src/plugins/index.ts
@@ -0,0 +1,3 @@
+import plugins from "plugins";
+
+console.log(plugins); \ No newline at end of file
diff --git a/src/preload.ts b/src/preload.ts
index 0fc7430..73d2eb5 100644
--- a/src/preload.ts
+++ b/src/preload.ts
@@ -1,14 +1,10 @@
import { contextBridge, webFrame } from "electron";
import { readFileSync } from "fs";
import { join } from "path";
-import Vencord from "./Vencord";
+import VencordNative from "./VencordNative";
-contextBridge.exposeInMainWorld("VencordNative", {
- getSettings: () => "hi"
-});
+contextBridge.exposeInMainWorld("VencordNative", VencordNative);
webFrame.executeJavaScript(readFileSync(join(__dirname, "renderer.js"), "utf-8"));
require(process.env.DISCORD_PRELOAD!);
-
-window.onload = () => console.log("hi"); \ No newline at end of file
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index ef008cd..e948309 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -1,4 +1 @@
-import { join } from 'path';
-
export const WEBPACK_CHUNK = "webpackChunkdiscord_app";
-// export const SETTINGS_DIR = join(process.env.DATA_DIR!, "settings");
diff --git a/src/utils/ipcEvents.ts b/src/utils/ipcEvents.ts
new file mode 100644
index 0000000..1920023
--- /dev/null
+++ b/src/utils/ipcEvents.ts
@@ -0,0 +1,3 @@
+export const IPC_QUICK_CSS_UPDATE = "VencordQuickCssUpdate";
+export const IPC_GET_QUICK_CSS = "VencordGetQuickCss";
+export const IPC_GET_SETTINGS_DIR = "VencordGetSettingsDir"; \ No newline at end of file
diff --git a/src/utils/quickCss.ts b/src/utils/quickCss.ts
new file mode 100644
index 0000000..573eccc
--- /dev/null
+++ b/src/utils/quickCss.ts
@@ -0,0 +1,6 @@
+document.addEventListener("DOMContentLoaded", async () => {
+ const style = document.createElement("style");
+ document.head.appendChild(style);
+ VencordNative.handleQuickCssUpdate((css: string) => style.innerText = css);
+ style.innerText = await VencordNative.getQuickCss();
+}); \ No newline at end of file