diff --git a/src/components/organisms/FileTreePane/FileTreePane.tsx b/src/components/organisms/FileTreePane/FileTreePane.tsx index 317301089e..b091cb9929 100644 --- a/src/components/organisms/FileTreePane/FileTreePane.tsx +++ b/src/components/organisms/FileTreePane/FileTreePane.tsx @@ -675,6 +675,9 @@ const FileTreePane = () => { setFolder(data); } }); + return () => { + ipcRenderer.removeListener('set-root-folder', onExecutedFrom); + }; }, []); useEffect(() => { diff --git a/src/redux/services/fileMonitor.ts b/src/redux/services/fileMonitor.ts index 957c51071f..66c10dacbe 100644 --- a/src/redux/services/fileMonitor.ts +++ b/src/redux/services/fileMonitor.ts @@ -15,57 +15,55 @@ let watcher: FSWatcher; export function monitorRootFolder(folder: string, appConfig: AppConfig, dispatch: AppDispatch) { if (watcher) { - const watched = Object.keys(watcher.getWatched()); - watcher.unwatch(watched); - watcher.add(folder); - } else { - watcher = watch(folder, { - ignored: appConfig.scanExcludes, - ignoreInitial: true, - persistent: true, - usePolling: true, - interval: 1000, - }); + watcher.close(); + } - watcher - .on( - 'add', - debounceWithPreviousArgs((args: any[]) => { - const paths: Array = args.map(arg => arg[0]); - dispatch(multiplePathsAdded({paths, appConfig})); - }, 1000) - ) - .on( - 'addDir', - debounceWithPreviousArgs((args: any[]) => { - const paths: Array = args.map(arg => arg[0]); - dispatch(multiplePathsAdded({paths, appConfig})); - }, 1000) - ) - .on( - 'change', - debounceWithPreviousArgs((args: any[]) => { - const paths: Array = args.map(arg => arg[0]); - dispatch(multipleFilesChanged({paths, appConfig})); - }, 1000) - ) - .on( - 'unlink', - debounceWithPreviousArgs((args: any[]) => { - const paths: Array = args.map(arg => arg[0]); - dispatch(multiplePathsRemoved(paths)); - }, 1000) - ) - .on( - 'unlinkDir', - debounceWithPreviousArgs((args: any[]) => { - const paths: Array = args.map(arg => arg[0]); - dispatch(multiplePathsRemoved(paths)); - }, 1000) - ); + watcher = watch(folder, { + ignored: appConfig.scanExcludes, + ignoreInitial: true, + persistent: true, + usePolling: true, + interval: 1000, + }); - watcher - /* eslint-disable no-console */ - .on('error', error => console.log(`Watcher error: ${error}`)); - } + watcher + .on( + 'add', + debounceWithPreviousArgs((args: any[]) => { + const paths: Array = args.map(arg => arg[0]); + dispatch(multiplePathsAdded({paths, appConfig})); + }, 1000) + ) + .on( + 'addDir', + debounceWithPreviousArgs((args: any[]) => { + const paths: Array = args.map(arg => arg[0]); + dispatch(multiplePathsAdded({paths, appConfig})); + }, 1000) + ) + .on( + 'change', + debounceWithPreviousArgs((args: any[]) => { + const paths: Array = args.map(arg => arg[0]); + dispatch(multipleFilesChanged({paths, appConfig})); + }, 1000) + ) + .on( + 'unlink', + debounceWithPreviousArgs((args: any[]) => { + const paths: Array = args.map(arg => arg[0]); + dispatch(multiplePathsRemoved(paths)); + }, 1000) + ) + .on( + 'unlinkDir', + debounceWithPreviousArgs((args: any[]) => { + const paths: Array = args.map(arg => arg[0]); + dispatch(multiplePathsRemoved(paths)); + }, 1000) + ); + + watcher + /* eslint-disable no-console */ + .on('error', error => console.log(`Watcher error: ${error}`)); }