Modified dependencies

pull/1575/head
ioedeveloper 4 years ago
parent 0881f25d57
commit d41396e185
  1. 57
      apps/remix-ide/src/app/panels/file-panel.js
  2. 12
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -47,17 +47,14 @@ const profile = {
module.exports = class Filepanel extends ViewPlugin { module.exports = class Filepanel extends ViewPlugin {
constructor (appManager) { constructor (appManager) {
super(profile) super(profile)
this._components = {} this.registry = globalRegistry
this._components.registry = globalRegistry this.fileProviders = this.registry.get('fileproviders').api
this._deps = { this.fileManager = this.registry.get('filemanager').api
fileProviders: this._components.registry.get('fileproviders').api,
fileManager: this._components.registry.get('filemanager').api
}
this.el = document.createElement('div') this.el = document.createElement('div')
this.el.setAttribute('id', 'fileExplorerView') this.el.setAttribute('id', 'fileExplorerView')
this.remixdHandle = new RemixdHandle(this._deps.fileProviders.localhost, appManager) this.remixdHandle = new RemixdHandle(this.fileProviders.localhost, appManager)
this.gitHandle = new GitHandle() this.gitHandle = new GitHandle()
this.hardhatHandle = new HardhatHandle() this.hardhatHandle = new HardhatHandle()
this.slitherHandle = new SlitherHandle() this.slitherHandle = new SlitherHandle()
@ -83,11 +80,11 @@ module.exports = class Filepanel extends ViewPlugin {
workspaceRenamed={this.workspaceRenamed.bind(this)} workspaceRenamed={this.workspaceRenamed.bind(this)}
workspaceDeleted={this.workspaceDeleted.bind(this)} workspaceDeleted={this.workspaceDeleted.bind(this)}
workspaceCreated={this.workspaceCreated.bind(this)} workspaceCreated={this.workspaceCreated.bind(this)}
workspace={this._deps.fileProviders.workspace} workspace={this.fileProviders.workspace}
browser={this._deps.fileProviders.browser} browser={this.fileProviders.browser}
localhost={this._deps.fileProviders.localhost} localhost={this.fileProviders.localhost}
fileManager={this._deps.fileManager} fileManager={this.fileManager}
registry={this._components.registry} registry={this.registry}
plugin={this} plugin={this}
request={this.request} request={this.request}
workspaces={this.workspaces} workspaces={this.workspaces}
@ -131,8 +128,8 @@ module.exports = class Filepanel extends ViewPlugin {
async getWorkspaces () { async getWorkspaces () {
const result = new Promise((resolve, reject) => { const result = new Promise((resolve, reject) => {
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath const workspacesPath = this.fileProviders.workspace.workspacesPath
this._deps.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => { this.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => {
if (error) { if (error) {
console.error(error) console.error(error)
return reject(error) return reject(error)
@ -161,7 +158,7 @@ module.exports = class Filepanel extends ViewPlugin {
let loadedFromGist = false let loadedFromGist = false
if (params.gist) { if (params.gist) {
await this.processCreateWorkspace('gist-sample') await this.processCreateWorkspace('gist-sample')
this._deps.fileProviders.workspace.setWorkspace('gist-sample') this.fileProviders.workspace.setWorkspace('gist-sample')
this.initialWorkspace = 'gist-sample' this.initialWorkspace = 'gist-sample'
loadedFromGist = gistHandler.loadFromGist(params, this._deps.fileManager) loadedFromGist = gistHandler.loadFromGist(params, this._deps.fileManager)
} }
@ -170,23 +167,23 @@ module.exports = class Filepanel extends ViewPlugin {
if (params.code || params.url) { if (params.code || params.url) {
try { try {
await this.processCreateWorkspace('code-sample') await this.processCreateWorkspace('code-sample')
this._deps.fileProviders.workspace.setWorkspace('code-sample') this.fileProviders.workspace.setWorkspace('code-sample')
let path = '' let path = ''
let content = '' let content = ''
if (params.code) { if (params.code) {
var hash = bufferToHex(keccakFromString(params.code)) var hash = bufferToHex(keccakFromString(params.code))
path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
content = atob(params.code) content = atob(params.code)
await this._deps.fileProviders.workspace.set(path, content) await this.fileProviders.workspace.set(path, content)
} }
if (params.url) { if (params.url) {
const data = await this.call('contentImport', 'resolve', params.url) const data = await this.call('contentImport', 'resolve', params.url)
path = data.cleanUrl path = data.cleanUrl
content = data.content content = data.content
await this._deps.fileProviders.workspace.set(path, content) await this.fileProviders.workspace.set(path, content)
} }
this.initialWorkspace = 'code-sample' this.initialWorkspace = 'code-sample'
await this._deps.fileManager.openFile(path) await this.fileManager.openFile(path)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
@ -197,19 +194,19 @@ module.exports = class Filepanel extends ViewPlugin {
this.appManager.on('manager', 'pluginDeactivated', self.removePluginActions.bind(this)) this.appManager.on('manager', 'pluginDeactivated', self.removePluginActions.bind(this))
// insert example contracts if there are no files to show // insert example contracts if there are no files to show
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._deps.fileProviders.browser.resolveDirectory('/', async (error, filesList) => { this.fileProviders.browser.resolveDirectory('/', async (error, filesList) => {
if (error) return reject(error) if (error) return reject(error)
if (Object.keys(filesList).length === 0) { if (Object.keys(filesList).length === 0) {
await this.createWorkspace('default_workspace') await this.createWorkspace('default_workspace')
resolve('default_workspace') resolve('default_workspace')
} else { } else {
this._deps.fileProviders.browser.resolveDirectory('.workspaces', async (error, filesList) => { this.fileProviders.browser.resolveDirectory('.workspaces', async (error, filesList) => {
if (error) return reject(error) if (error) return reject(error)
if (Object.keys(filesList).length > 0) { if (Object.keys(filesList).length > 0) {
const workspacePath = Object.keys(filesList)[0].split('/').filter(val => val) const workspacePath = Object.keys(filesList)[0].split('/').filter(val => val)
const workspaceName = workspacePath[workspacePath.length - 1] const workspaceName = workspacePath[workspacePath.length - 1]
this._deps.fileProviders.workspace.setWorkspace(workspaceName) this.fileProviders.workspace.setWorkspace(workspaceName)
return resolve(workspaceName) return resolve(workspaceName)
} }
return reject(new Error('Can\'t find available workspace.')) return reject(new Error('Can\'t find available workspace.'))
@ -228,8 +225,8 @@ module.exports = class Filepanel extends ViewPlugin {
} }
async processCreateWorkspace (name) { async processCreateWorkspace (name) {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this.fileProviders.workspace
const browserProvider = this._deps.fileProviders.browser const browserProvider = this.fileProviders.browser
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name
const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath
const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath) const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath)
@ -240,8 +237,8 @@ module.exports = class Filepanel extends ViewPlugin {
} }
async workspaceExists (name) { async workspaceExists (name) {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this.fileProviders.workspace
const browserProvider = this._deps.fileProviders.browser const browserProvider = this.fileProviders.browser
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name
return browserProvider.exists(workspacePath) return browserProvider.exists(workspacePath)
} }
@ -251,7 +248,7 @@ module.exports = class Filepanel extends ViewPlugin {
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed')
if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists') if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists')
else { else {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this.fileProviders.workspace
await this.processCreateWorkspace(workspaceName) await this.processCreateWorkspace(workspaceName)
workspaceProvider.setWorkspace(workspaceName) workspaceProvider.setWorkspace(workspaceName)
await this.request.setWorkspace(workspaceName) // tells the react component to switch to that workspace await this.request.setWorkspace(workspaceName) // tells the react component to switch to that workspace
@ -271,8 +268,8 @@ module.exports = class Filepanel extends ViewPlugin {
if (!workspaceName) throw new Error('name cannot be empty') if (!workspaceName) throw new Error('name cannot be empty')
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed')
if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists') if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists')
const browserProvider = this._deps.fileProviders.browser const browserProvider = this.fileProviders.browser
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath const workspacesPath = this.fileProviders.workspace.workspacesPath
browserProvider.rename('browser/' + workspacesPath + '/' + oldName, 'browser/' + workspacesPath + '/' + workspaceName, true) browserProvider.rename('browser/' + workspacesPath + '/' + oldName, 'browser/' + workspacesPath + '/' + workspaceName, true)
} }
@ -284,7 +281,7 @@ module.exports = class Filepanel extends ViewPlugin {
this.call('manager', 'deactivatePlugin', 'remixd') this.call('manager', 'deactivatePlugin', 'remixd')
} }
if (setEvent) { if (setEvent) {
this._deps.fileManager.setMode(workspace.isLocalhost ? 'localhost' : 'browser') this.fileManager.setMode(workspace.isLocalhost ? 'localhost' : 'browser')
this.emit('setWorkspace', workspace) this.emit('setWorkspace', workspace)
} }
} }

@ -18,15 +18,16 @@ export const initWorkspace = (filePanelPlugin) => async (dispatch: React.Dispatc
const queryParams = new QueryParams() const queryParams = new QueryParams()
const gistHandler = new GistHandler() const gistHandler = new GistHandler()
const params = queryParams.get() const params = queryParams.get()
let initialWorkspace = ''
// get the file from gist // get the file from gist
let loadedFromGist = false let loadedFromGist = false
if (params.gist) { if (params.gist) {
await processCreateWorkspace('gist-sample') await processCreateWorkspace('gist-sample')
plugin.initialWorkspace = 'gist-sample' initialWorkspace = 'gist-sample'
loadedFromGist = gistHandler.loadFromGist(params, plugin.fileManager) loadedFromGist = gistHandler.loadFromGist(params, plugin.fileManager)
} }
if (loadedFromGist) return if (loadedFromGist) return dispatch(setCurrentWorkspace(initialWorkspace))
if (params.code) { if (params.code) {
try { try {
@ -36,15 +37,15 @@ export const initWorkspace = (filePanelPlugin) => async (dispatch: React.Dispatc
const path = fileName const path = fileName
await plugin.fileProviders.workspace.set(path, atob(params.code)) await plugin.fileProviders.workspace.set(path, atob(params.code))
plugin.initialWorkspace = 'code-sample' initialWorkspace = 'code-sample'
await plugin.fileManager.openFile(fileName) await plugin.fileManager.openFile(fileName)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
return return dispatch(setCurrentWorkspace(initialWorkspace))
} }
return new Promise((resolve, reject) => { initialWorkspace = await new Promise((resolve, reject) => {
plugin.fileProviders.browser.resolveDirectory('/', async (error, filesList) => { plugin.fileProviders.browser.resolveDirectory('/', async (error, filesList) => {
if (error) return reject(error) if (error) return reject(error)
if (Object.keys(filesList).length === 0) { if (Object.keys(filesList).length === 0) {
@ -65,6 +66,7 @@ export const initWorkspace = (filePanelPlugin) => async (dispatch: React.Dispatc
} }
}) })
}) })
return dispatch(setCurrentWorkspace(initialWorkspace))
} }
const processCreateWorkspace = async (name: string) => { const processCreateWorkspace = async (name: string) => {

Loading…
Cancel
Save