Close Ipc FS watchers if window is closed
This commit is contained in:
		
							parent
							
								
									19799767ad
								
							
						
					
					
						commit
						102842d528
					
				
					 1 changed files with 11 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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 () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue