Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load plugins from parameters #2514

Merged
merged 5 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment to explain what this class is about.

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
}