diff options
author | Vendicated <vendicated@riseup.net> | 2022-09-01 21:40:26 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-09-01 21:40:26 +0200 |
commit | 78deb0ebad40e4746796994345143120e3566b6b (patch) | |
tree | 270e94fa689bc809b75cbee35801299b26324427 | |
parent | 7ce37f858c0a1e09e1f6497fbd32b172cc9b3c6c (diff) | |
download | Vencord-78deb0ebad40e4746796994345143120e3566b6b.tar.gz Vencord-78deb0ebad40e4746796994345143120e3566b6b.tar.bz2 Vencord-78deb0ebad40e4746796994345143120e3566b6b.zip |
Fix settings corrupting
-rw-r--r-- | src/ipcMain.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/ipcMain.ts b/src/ipcMain.ts index 38a16ab..80bff55 100644 --- a/src/ipcMain.ts +++ b/src/ipcMain.ts @@ -23,12 +23,18 @@ function readSettings() { ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR); ipcMain.handle(IpcEvents.GET_QUICK_CSS, () => readCss()); -// .on because we need Settings synchronously (ipcRenderer.sendSync) -ipcMain.on(IpcEvents.GET_SETTINGS, (e) => e.returnValue = readSettings()); -ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => void writeFile(SETTINGS_FILE, s)); ipcMain.handle(IpcEvents.OPEN_PATH, (_, path) => shell.openPath(path)); ipcMain.handle(IpcEvents.OPEN_EXTERNAL, (_, url) => shell.openExternal(url)); +// .on because we need Settings synchronously (ipcRenderer.sendSync) +ipcMain.on(IpcEvents.GET_SETTINGS, (e) => e.returnValue = readSettings()); + +// This is required because otherwise calling SET_SETTINGS in quick succession may lead to concurrent writes +let settingsWriteQueue = Promise.resolve(); +ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => { + settingsWriteQueue = settingsWriteQueue.then(() => writeFile(SETTINGS_FILE, s)); +}); + export function initIpc(mainWindow: BrowserWindow) { open(QUICKCSS_PATH, "a+").then(fd => { fd.close(); |