diff options
Diffstat (limited to 'src/ipcMain')
-rw-r--r-- | src/ipcMain/index.ts | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/ipcMain/index.ts b/src/ipcMain/index.ts index caa4e34..dc05079 100644 --- a/src/ipcMain/index.ts +++ b/src/ipcMain/index.ts @@ -22,8 +22,10 @@ import { open, readFile, writeFile } from "fs/promises"; import { join } from "path"; import { debounce } from "../utils/debounce"; import IpcEvents from "../utils/IpcEvents"; +import monacoHtml from "@fileContent/../components/monacoWin.html;base64"; import "./updater"; +import { Queue } from "../utils/Queue"; const DATA_DIR = process.env.VENCORD_USER_DATA_DIR ?? ( process.env.DISCORD_USER_DATA_DIR @@ -71,15 +73,19 @@ ipcMain.handle(IpcEvents.OPEN_EXTERNAL, (_, url) => { shell.openExternal(url); }); +const cssWriteQueue = new Queue(); +const settingsWriteQueue = new Queue(); ipcMain.handle(IpcEvents.GET_QUICK_CSS, () => readCss()); +ipcMain.handle(IpcEvents.SET_QUICK_CSS, (_, css) => + cssWriteQueue.add(() => writeFile(QUICKCSS_PATH, css)) +); ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR); ipcMain.on(IpcEvents.GET_SETTINGS, e => e.returnValue = readSettings()); -let settingsWriteQueue = Promise.resolve(); ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => { - settingsWriteQueue = settingsWriteQueue.then(() => writeFile(SETTINGS_FILE, s)); + settingsWriteQueue.add(() => writeFile(SETTINGS_FILE, s)); }); @@ -91,3 +97,13 @@ export function initIpc(mainWindow: BrowserWindow) { }, 50)); }); } + +ipcMain.handle(IpcEvents.OPEN_MONACO_EDITOR, async () => { + const win = new BrowserWindow({ + title: "QuickCss Editor", + webPreferences: { + preload: join(__dirname, "preload.js"), + } + }); + await win.loadURL(`data:text/html;base64,${monacoHtml}`); +}); |