Skip to content

Commit

Permalink
Merge pull request #2514 from ethereum/loadPluginsFromParameters
Browse files Browse the repository at this point in the history
Load plugins from parameters
  • Loading branch information
yann300 committed Jan 7, 2020
2 parents 8dcf005 + a242047 commit 47cfb63
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global localStorage */
'use strict'

var isElectron = require('is-electron')
Expand Down Expand Up @@ -208,7 +207,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org

// APP_MANAGER
const appManager = new RemixAppManager({})
const workspace = JSON.parse(localStorage.getItem('workspace'))
const workspace = appManager.pluginLoader.get()

// SERVICES
// ----------------- import content servive ----------------------------
Expand Down
52 changes: 47 additions & 5 deletions src/remixAppManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { PluginEngine, IframePlugin } from '@remixproject/engine'
import { EventEmitter } from 'events'
import { PermissionHandler } from './app/ui/persmission-handler'
import QueryParams from './lib/query-params'

const requiredModules = [ // services + layout views + system views
'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport',
Expand All @@ -19,15 +20,13 @@ export class RemixAppManager extends PluginEngine {
constructor (plugins) {
super(plugins, settings)
this.event = new EventEmitter()
this.donotAutoReload = ['remixd'] // that would be a bad practice to force loading some plugins at page load.
this.registered = {}
this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/profile.json'
this.pluginLoader = new PluginLoader()
}

onActivated (plugin) {
if (!this.donotAutoReload.includes(plugin.name)) {
localStorage.setItem('workspace', JSON.stringify(this.actives))
}
this.pluginLoader.set(plugin, this.actives)
this.event.emit('activate', plugin.name)
}

Expand All @@ -46,7 +45,7 @@ export class RemixAppManager extends PluginEngine {
}

onDeactivated (plugin) {
localStorage.setItem('workspace', JSON.stringify(this.actives))
this.pluginLoader.set(plugin, this.actives)
this.event.emit('deactivate', plugin.name)
}

Expand Down Expand Up @@ -232,3 +231,46 @@ export class RemixAppManager extends PluginEngine {
]
}
}

/** @class Reference loaders.
* A loader is a get,set based object which load a workspace from a defined sources.
* (localStorage, queryParams)
**/
class PluginLoader {
get currentLoader () {
return this.loaders[this.current]
}

constructor () {
const queryParams = new QueryParams()
this.donotAutoReload = ['remixd'] // that would be a bad practice to force loading some plugins at page load.
this.loaders = {}
this.loaders['localStorage'] = {
set: (plugin, actives) => {
if (!this.donotAutoReload.includes(plugin.name)) {
localStorage.setItem('workspace', JSON.stringify(actives))
}
},
get: () => { return JSON.parse(localStorage.getItem('workspace')) }
}

this.loaders['queryParams'] = {
set: () => {},
get: () => {
const { plugins } = queryParams.get()
if (!plugins) return []
return plugins.split(',')
}
}

this.current = queryParams.get()['plugins'] ? 'queryParams' : 'localStorage'
}

set (plugin, actives) {
this.currentLoader.set(plugin, actives)
}

get () {
return this.currentLoader.get()
}
}
16 changes: 9 additions & 7 deletions test-browser/helpers/init.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module.exports = function (browser, callback) {
module.exports = function (browser, callback, url, preloadPlugins = true) {
browser
.url('http://127.0.0.1:8080')
.url(url || 'http://127.0.0.1:8080')
.injectScript('test-browser/helpers/applytestmode.js', function () {
browser.resizeWindow(2560, 1440, () => {
initModules(browser, () => {
browser.clickLaunchIcon('solidity').click('#autoCompile')
.perform(function () {
callback()
if (preloadPlugins) {
initModules(browser, () => {
browser.clickLaunchIcon('solidity').click('#autoCompile')
.perform(function () {
callback()
})
})
})
} else callback()
})
})
}
Expand Down
17 changes: 17 additions & 0 deletions test-browser/tests/workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'
const init = require('../helpers/init')
const sauce = require('./sauce')

module.exports = {
before: function (browser, done) {
init(browser, done, 'http://127.0.0.1:8080?plugins=solidity,udapp', false)
},
'CheckSolidityActivatedAndUDapp': function (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('solidity')
.clickLaunchIcon('udapp')
.end()
},
tearDown: sauce
}

0 comments on commit 47cfb63

Please sign in to comment.