Merge pull request #4346 from ethereum/fixwatcherdesktop

Fixwatcherdesktop
pull/4365/head
bunsenstraat 11 months ago committed by GitHub
commit a42fcebef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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']
// 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.'
})
}
})
}
}

@ -148,9 +148,13 @@ class FSPluginClient extends ElectronBasePluginClient {
}
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,
})
this.emit('change', 'unlinkDir', path)
await this.watch()
}
async unlink(path: string): Promise<void> {
@ -199,7 +203,9 @@ class FSPluginClient extends ElectronBasePluginClient {
}
async watch(): Promise<void> {
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<void> {
@ -274,7 +293,7 @@ class FSPluginClient extends ElectronBasePluginClient {
writeConfig(config)
}
async selectFolder(path?: string): Promise<string> {
async selectFolder(path?: string, title?: string): Promise<string> {
let dirs: string[] | undefined
if (!path) {
dirs = dialog.showOpenDialogSync(this.window, {

@ -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

Loading…
Cancel
Save