Skip to content

Commit

Permalink
Close Ipc FS watchers if window is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckyz committed Mar 7, 2024
1 parent 1979976 commit 102842d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { debounce } from "@utils/debounce";
import { IpcEvents } from "@utils/IpcEvents";
import { Queue } from "@utils/Queue";
import { BrowserWindow, ipcMain, shell, systemPreferences } from "electron";
import { mkdirSync, readFileSync, watch } from "fs";
import { FSWatcher, mkdirSync, readFileSync, watch } from "fs";
import { open, readdir, readFile, writeFile } from "fs/promises";
import { join, normalize } from "path";

Expand Down Expand Up @@ -126,16 +126,23 @@ ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => {


export function initIpc(mainWindow: BrowserWindow) {
let quickCssWatcher: FSWatcher | undefined;

open(QUICKCSS_PATH, "a+").then(fd => {
fd.close();
watch(QUICKCSS_PATH, { persistent: false }, debounce(async () => {
quickCssWatcher = watch(QUICKCSS_PATH, { persistent: false }, debounce(async () => {
mainWindow.webContents.postMessage(IpcEvents.QUICK_CSS_UPDATE, await readCss());
}, 50));
});
}).catch(() => { });

watch(THEMES_DIR, { persistent: false }, debounce(() => {
const themesWatcher = watch(THEMES_DIR, { persistent: false }, debounce(() => {
mainWindow.webContents.postMessage(IpcEvents.THEME_UPDATE, void 0);
}));

mainWindow.once("closed", () => {
quickCssWatcher?.close();
themesWatcher.close();
});
}

ipcMain.handle(IpcEvents.OPEN_MONACO_EDITOR, async () => {
Expand Down

0 comments on commit 102842d

Please sign in to comment.