diff --git a/apps/remix-ide/src/app/plugins/electron/fsPlugin.ts b/apps/remix-ide/src/app/plugins/electron/fsPlugin.ts index 09da052127..5c04d5d841 100644 --- a/apps/remix-ide/src/app/plugins/electron/fsPlugin.ts +++ b/apps/remix-ide/src/app/plugins/electron/fsPlugin.ts @@ -18,6 +18,8 @@ export class fsPlugin extends ElectronPlugin { }) this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'setWorkingDir', 'getRecentFolders', 'openWindow'] + + // List of commands all filesystems are expected to provide. `rm` is not // included since it may not exist and must be handled as a special case const commands = [ @@ -114,6 +116,7 @@ export class fsPlugin extends ElectronPlugin { } + @@ -133,6 +136,14 @@ export class fsPlugin extends ElectronPlugin { workingDir = path await this.call('fileManager', 'refresh') }) + this.on('fs', 'error', async (error: string) => { + if(error === 'ENOSPC'){ + this.call('notification', 'alert', { + id: 'fsError', + message: 'Cannot watch file changes. There are too many files in your project.' + }) + } + }) } } \ No newline at end of file diff --git a/apps/remixdesktop/src/plugins/fsPlugin.ts b/apps/remixdesktop/src/plugins/fsPlugin.ts index ccf15e6f6a..830ff7aa0b 100644 --- a/apps/remixdesktop/src/plugins/fsPlugin.ts +++ b/apps/remixdesktop/src/plugins/fsPlugin.ts @@ -148,9 +148,13 @@ class FSPluginClient extends ElectronBasePluginClient { } async rmdir(path: string): Promise { - return fs.rm(this.fixPath(path), { + if (this.watcher) await this.watcher.close() + await fs.rm(this.fixPath(path), { recursive: true, }) + this.emit('change', 'unlinkDir', path) + await this.watch() + } async unlink(path: string): Promise { @@ -199,7 +203,9 @@ class FSPluginClient extends ElectronBasePluginClient { } async watch(): Promise { + if (this.watcher) this.watcher.close() + try{ this.watcher = chokidar .watch(this.workingDir, { ignorePermissionErrors: true, @@ -207,11 +213,14 @@ class FSPluginClient extends ElectronBasePluginClient { ignored: [ '**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows ], + depth: 20 + }) .on('all', async (eventName, path, stats) => { let pathWithoutPrefix = path.replace(this.workingDir, '') pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1) + if (eventName === 'change') { // remove workingDir from path const newContent = await fs.readFile(path, 'utf-8') @@ -233,6 +242,16 @@ class FSPluginClient extends ElectronBasePluginClient { } } }) + .on('error', error => { + this.watcher.close() + if(error.message.includes('ENOSPC')) { + this.emit('error', 'ENOSPC') + } + console.log(`Watcher error: ${error}`) + }) + }catch(e){ + console.log('error watching', e) + } } async closeWatch(): Promise { @@ -274,7 +293,7 @@ class FSPluginClient extends ElectronBasePluginClient { writeConfig(config) } - async selectFolder(path?: string): Promise { + async selectFolder(path?: string, title?: string): Promise { let dirs: string[] | undefined if (!path) { dirs = dialog.showOpenDialogSync(this.window, { diff --git a/apps/remixdesktop/src/plugins/templates.ts b/apps/remixdesktop/src/plugins/templates.ts index b5882ea947..4ede3b1742 100644 --- a/apps/remixdesktop/src/plugins/templates.ts +++ b/apps/remixdesktop/src/plugins/templates.ts @@ -44,7 +44,7 @@ class TemplatesPluginClient extends ElectronBasePluginClient { async loadTemplateInNewWindow (files: any) { - let folder = await this.call('fs' as any, 'selectFolder') + let folder = await this.call('fs' as any, 'selectFolder', 'Select or create a folder to load the template in') if (!folder || folder === '') return // @ts-ignore