watcher fix

pull/4346/head
bunsenstraat 11 months ago
parent f5486070aa
commit f9f5b39988
  1. 11
      apps/remix-ide/src/app/plugins/electron/fsPlugin.ts
  2. 23
      apps/remixdesktop/src/plugins/fsPlugin.ts
  3. 2
      apps/remixdesktop/src/plugins/templates.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'] 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 // 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 // included since it may not exist and must be handled as a special case
const commands = [ const commands = [
@ -119,6 +121,7 @@ export class fsPlugin extends ElectronPlugin {
} }
@ -133,6 +136,14 @@ export class fsPlugin extends ElectronPlugin {
workingDir = path workingDir = path
await this.call('fileManager', 'refresh') 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.'
})
}
})
} }
} }

@ -148,9 +148,13 @@ class FSPluginClient extends ElectronBasePluginClient {
} }
async rmdir(path: string): Promise<void> { async rmdir(path: string): Promise<void> {
return fs.rm(this.fixPath(path), { if (this.watcher) await this.watcher.close()
await fs.rm(this.fixPath(path), {
recursive: true, recursive: true,
}) })
this.emit('change', 'unlinkDir', path)
await this.watch()
} }
async unlink(path: string): Promise<void> { async unlink(path: string): Promise<void> {
@ -199,7 +203,9 @@ class FSPluginClient extends ElectronBasePluginClient {
} }
async watch(): Promise<void> { async watch(): Promise<void> {
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
try{
this.watcher = chokidar this.watcher = chokidar
.watch(this.workingDir, { .watch(this.workingDir, {
ignorePermissionErrors: true, ignorePermissionErrors: true,
@ -207,11 +213,14 @@ class FSPluginClient extends ElectronBasePluginClient {
ignored: [ ignored: [
'**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows '**/.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) => { .on('all', async (eventName, path, stats) => {
let pathWithoutPrefix = path.replace(this.workingDir, '') let pathWithoutPrefix = path.replace(this.workingDir, '')
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix)
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1) if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1)
if (eventName === 'change') { if (eventName === 'change') {
// remove workingDir from path // remove workingDir from path
const newContent = await fs.readFile(path, 'utf-8') 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<void> { async closeWatch(): Promise<void> {
@ -274,7 +293,7 @@ class FSPluginClient extends ElectronBasePluginClient {
writeConfig(config) writeConfig(config)
} }
async selectFolder(path?: string): Promise<string> { async selectFolder(path?: string, title?: string): Promise<string> {
let dirs: string[] | undefined let dirs: string[] | undefined
if (!path) { if (!path) {
dirs = dialog.showOpenDialogSync(this.window, { dirs = dialog.showOpenDialogSync(this.window, {

@ -44,7 +44,7 @@ class TemplatesPluginClient extends ElectronBasePluginClient {
async loadTemplateInNewWindow (files: any) { 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 if (!folder || folder === '') return
// @ts-ignore // @ts-ignore

Loading…
Cancel
Save