From fcec4fef36743aaf9c80cf0c5c9d70b83c8d2eae Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 6 May 2020 08:59:29 +0000 Subject: [PATCH] Changed fileExplorer to async/await to fix remixd error --- src/app/files/file-explorer.js | 15 ++++++++++----- src/app/files/fileManager.js | 8 ++++---- src/app/files/remixDProvider.js | 7 +++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index eb8be63682..460777222f 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -234,8 +234,11 @@ function fileExplorer (localRegistry, files, menuItems) { const currentFoldername = extractNameFromKey(key) modalDialogCustom.confirm(`Confirm to delete folder`, `Are you sure you want to delete ${currentFoldername} folder?`, - () => { - if (!files.remove(key)) { + async () => { + const fileManager = self._deps.fileManager + const removeFolder = await fileManager.rmdir(key) + + if (!removeFolder) { tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`) } else { self.updatePath('browser') @@ -578,13 +581,15 @@ fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') { let self = this modalDialogCustom.prompt('Create new file', 'File Name (e.g Untitled.sol)', 'Untitled.sol', (input) => { if (!input) input = 'New file' - helper.createNonClashingName(parentFolder + '/' + input, self.files, (error, newName) => { + helper.createNonClashingName(parentFolder + '/' + input, self.files, async (error, newName) => { if (error) return tooltip('Failed to create file ' + newName + ' ' + error) + const fileManager = self._deps.fileManager + const createFile = await fileManager.writeFile(newName, '') - if (!self.files.set(newName, '')) { + if (!createFile) { tooltip('Failed to create file ' + newName) } else { - self._deps.fileManager.open(newName) + await fileManager.open(newName) if (newName.includes('_test.sol')) { self.events.trigger('newTestFileCreated', [newName]) } diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 9ad5795978..e52b373a38 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -158,9 +158,9 @@ class FileManager extends Plugin { async writeFile (path, data) { if (await this.exists(path)) { await this._handleIsFile(path, `Cannot write file ${path}`) - this.setFile(path, data) + return await this.setFile(path, data) } else { - this.setFile(path, data) + return await this.setFile(path, data) } } @@ -262,7 +262,7 @@ class FileManager extends Plugin { const provider = this.fileProviderOf(path) - return provider.remove(path) + return await provider.remove(path) } init () { @@ -385,7 +385,7 @@ class FileManager extends Plugin { `, '', { time: 3000 }) } } - this._setFileInternal(path, content) + return await this._setFileInternal(path, content) } _setFileInternal (path, content) { diff --git a/src/app/files/remixDProvider.js b/src/app/files/remixDProvider.js index cd0255a2bb..5485454c9d 100644 --- a/src/app/files/remixDProvider.js +++ b/src/app/files/remixDProvider.js @@ -118,9 +118,9 @@ module.exports = class RemixDProvider { return this._readOnlyMode || this._readOnlyFiles[path] === 1 } - remove (path) { + async remove (path) { var unprefixedpath = this.removePrefix(path) - this._remixd.call('sharedfolder', 'remove', {path: unprefixedpath}, (error, result) => { + const callId = await this._remixd.call('sharedfolder', 'remove', {path: unprefixedpath}, (error, result) => { if (error) console.log(error) var path = this.type + '/' + unprefixedpath delete this.filesContent[path] @@ -128,6 +128,9 @@ module.exports = class RemixDProvider { this.event.trigger('fileRemoved', [path]) }) }) + + await this._remixd.receiveResponse(callId) + return true } rename (oldPath, newPath, isFolder) {