2023-04-04 11:40:03 +09:00
|
|
|
import { app, ipcMain, shell } from "electron";
|
2023-04-06 03:01:31 +09:00
|
|
|
import { readFileSync, watch } from "fs";
|
|
|
|
import { open, readFile } from "fs/promises";
|
2023-04-04 07:41:52 +09:00
|
|
|
import { join } from "path";
|
2023-04-06 03:01:31 +09:00
|
|
|
import { debounce } from "shared/utils/debounce";
|
2023-04-05 12:31:44 +09:00
|
|
|
import { FOCUS, GET_RENDERER_SCRIPT, GET_RENDERER_STYLES, GET_SETTINGS, GET_VENCORD_PRELOAD_FILE, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents";
|
2023-04-06 03:01:31 +09:00
|
|
|
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants";
|
2023-04-05 12:19:48 +09:00
|
|
|
import { mainWin } from "./mainWindow";
|
2023-04-04 11:40:03 +09:00
|
|
|
import { PlainSettings, setSettings } from "./settings";
|
2023-04-04 07:41:52 +09:00
|
|
|
|
2023-04-04 11:40:03 +09:00
|
|
|
ipcMain.on(GET_VENCORD_PRELOAD_FILE, e => {
|
2023-04-04 07:41:52 +09:00
|
|
|
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
|
|
|
|
});
|
2023-04-04 08:35:37 +09:00
|
|
|
|
2023-04-04 11:40:03 +09:00
|
|
|
ipcMain.on(GET_RENDERER_SCRIPT, e => {
|
|
|
|
e.returnValue = readFileSync(join(__dirname, "renderer.js"), "utf-8");
|
|
|
|
});
|
|
|
|
|
2023-04-05 12:31:44 +09:00
|
|
|
ipcMain.handle(GET_RENDERER_STYLES, () => readFile(join(__dirname, "renderer.css"), "utf-8"));
|
|
|
|
|
2023-04-04 11:40:03 +09:00
|
|
|
ipcMain.on(GET_SETTINGS, e => {
|
|
|
|
e.returnValue = PlainSettings;
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle(SET_SETTINGS, (_, settings) => {
|
|
|
|
setSettings(settings);
|
|
|
|
});
|
|
|
|
|
2023-04-04 08:35:37 +09:00
|
|
|
ipcMain.handle(RELAUNCH, () => {
|
|
|
|
app.relaunch();
|
|
|
|
app.exit();
|
|
|
|
});
|
2023-04-04 11:40:03 +09:00
|
|
|
|
2023-04-05 12:19:48 +09:00
|
|
|
ipcMain.handle(SHOW_ITEM_IN_FOLDER, (_, path) => {
|
2023-04-04 11:40:03 +09:00
|
|
|
shell.showItemInFolder(path);
|
|
|
|
});
|
2023-04-05 12:19:48 +09:00
|
|
|
|
|
|
|
ipcMain.handle(FOCUS, () => {
|
|
|
|
mainWin?.focus();
|
|
|
|
});
|
2023-04-06 03:01:31 +09:00
|
|
|
|
|
|
|
function readCss() {
|
|
|
|
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
|
|
|
|
}
|
|
|
|
|
|
|
|
open(VENCORD_QUICKCSS_FILE, "a+").then(fd => {
|
|
|
|
fd.close();
|
|
|
|
watch(VENCORD_QUICKCSS_FILE, { persistent: false }, debounce(async () => {
|
|
|
|
mainWin?.webContents.postMessage("VencordQuickCssUpdate", await readCss());
|
|
|
|
}, 50));
|
|
|
|
});
|