diff --git a/src/app.js b/src/app.js index 6df7b03935..bd928fdbad 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,3 @@ -/* global localStorage */ 'use strict' var isElectron = require('is-electron') @@ -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 ---------------------------- diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 5c99f01980..0d91fa36b2 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -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', @@ -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) } @@ -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) } @@ -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() + } +} diff --git a/test-browser/helpers/init.js b/test-browser/helpers/init.js index 1ce93a57d8..6e4fa7df6b 100644 --- a/test-browser/helpers/init.js +++ b/test-browser/helpers/init.js @@ -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() }) }) } diff --git a/test-browser/tests/workspace.js b/test-browser/tests/workspace.js new file mode 100644 index 0000000000..bf5069c5b5 --- /dev/null +++ b/test-browser/tests/workspace.js @@ -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 +}