aboutsummaryrefslogtreecommitdiff
path: root/src/ipcMain.ts
blob: c8fba3710397e3be52a3520ed76d0cf0fe047867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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());
        });
    });
}