aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ipcMain.ts12
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();