From 4b965623c3f11fbff9633e2661d0abb99e632b39 Mon Sep 17 00:00:00 2001 From: Rushikesh Tote Date: Thu, 9 Jun 2022 11:26:50 +0530 Subject: [PATCH] refactor --- src/preload.ts | 4 ++-- src/utils/watch.ts | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/preload.ts b/src/preload.ts index 761d38880..9f0a95f17 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -18,7 +18,7 @@ import { setWatchMappings, addWatchMapping, removeWatchMapping, - isFolderExists, + doesFolderExists, } from './utils/watch'; import path from 'path'; @@ -201,5 +201,5 @@ windowObject['ElectronAPIs'] = { addWatchMapping, removeWatchMapping, registerWatcherFunctions, - isFolderExists, + doesFolderExists, }; diff --git a/src/utils/watch.ts b/src/utils/watch.ts index d584a7e22..dcaa35b19 100644 --- a/src/utils/watch.ts +++ b/src/utils/watch.ts @@ -78,7 +78,7 @@ export async function getAllFilesFromDir(dirPath: string) { return electronFiles; } -export async function isFolderExists(dirPath: string) { +export async function doesFolderExists(dirPath: string) { return await fs .stat(dirPath) .then((stats) => { @@ -118,11 +118,11 @@ export function initWatcher(mainWindow: BrowserWindow) { export function registerWatcherFunctions( WatchServiceInstance: any, - add: (WatchServiceInstance: any, file: ElectronFile) => Promise, - remove: ( + addFile: (WatchServiceInstance: any, file: ElectronFile) => Promise, + removeFile: (WatchServiceInstance: any, path: string) => Promise, + removeFolder: ( WatchServiceInstance: any, - path: string, - isDir?: boolean + folderPath: string ) => Promise ) { ipcRenderer.removeAllListeners('watch-add'); @@ -130,21 +130,21 @@ export function registerWatcherFunctions( ipcRenderer.removeAllListeners('watch-unlink'); ipcRenderer.on('watch-add', async (_, filePath: string) => { filePath = filePath.split(path.sep).join(path.posix.sep); - await add(WatchServiceInstance, await getElectronFile(filePath)); + await addFile(WatchServiceInstance, await getElectronFile(filePath)); }); ipcRenderer.on('watch-change', async (_, filePath: string) => { filePath = filePath.split(path.sep).join(path.posix.sep); - await remove(WatchServiceInstance, filePath); - await add(WatchServiceInstance, await getElectronFile(filePath)); + await removeFile(WatchServiceInstance, filePath); + await addFile(WatchServiceInstance, await getElectronFile(filePath)); }); ipcRenderer.on( 'watch-unlink', async (_, filePath: string, isDir?: boolean) => { filePath = filePath.split(path.sep).join(path.posix.sep); if (isDir) { - await remove(WatchServiceInstance, filePath, true); + await removeFolder(WatchServiceInstance, filePath); } else { - await remove(WatchServiceInstance, filePath); + await removeFile(WatchServiceInstance, filePath); } } );