aboutsummaryrefslogtreecommitdiff
path: root/src/ipcMain.ts
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/ipcMain.ts
parentaf498e78291b67377aaf876c84143cdfe7c8b308 (diff)
downloadVencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.tar.gz
Vencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.tar.bz2
Vencord-876e622f4f61a4aa229ad69782d374335c3d8d6b.zip
Progress
Diffstat (limited to 'src/ipcMain.ts')
-rw-r--r--src/ipcMain.ts25
1 files changed, 25 insertions, 0 deletions
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());
+ });
+ });
+}