From 62a43de74fdfbfa196dbfba41fcc17c355c7f69e Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 6 Jan 2020 17:53:29 +0100 Subject: [PATCH 1/5] load workspace from localstorage or queryparams --- src/app.js | 2 +- src/remixAppManager.js | 46 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/app.js b/src/app.js index 6df7b039357..0e868a89193 100644 --- a/src/app.js +++ b/src/app.js @@ -208,7 +208,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 5c99f019806..4fbb3f63d29 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,40 @@ export class RemixAppManager extends PluginEngine { ] } } + +class PluginLoader { + 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: () => { + let plugins = queryParams.get()['plugins'] + if (!plugins) return [] + return plugins.split(',') + } + } + + this.current = queryParams.get()['plugins'] ? 'queryParams' : 'localStorage' + } + + set (plugin, actives) { + this.loaders[this.current].set(plugin, actives) + } + + get () { + return this.loaders[this.current].get() + } +} From 0a876d55e5ee3221f550cf1203a9c0ffe07fe3a2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 6 Jan 2020 18:00:49 +0100 Subject: [PATCH 2/5] add browser tests --- src/app.js | 1 - test-browser/helpers/init.js | 16 +++++++++------- test-browser/tests/workspace.js | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 test-browser/tests/workspace.js diff --git a/src/app.js b/src/app.js index 0e868a89193..bd928fdbad0 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,3 @@ -/* global localStorage */ 'use strict' var isElectron = require('is-electron') diff --git a/test-browser/helpers/init.js b/test-browser/helpers/init.js index 1ce93a57d89..6e4fa7df6bb 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 00000000000..e019f4392be --- /dev/null +++ b/test-browser/tests/workspace.js @@ -0,0 +1,17 @@ +'use strict' +var init = require('../helpers/init') +var 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 +} From a9bd0339e2af022ccdecd8d5112a47a9a3d86ed4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 7 Jan 2020 10:02:28 +0100 Subject: [PATCH 3/5] comment --- src/remixAppManager.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 4fbb3f63d29..727d900ffd5 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -232,6 +232,10 @@ 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 { constructor () { const queryParams = new QueryParams() From 1a12675b3994e4ae44d70ac128a5a0a3c8749e35 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 7 Jan 2020 10:02:44 +0100 Subject: [PATCH 4/5] use getter --- src/remixAppManager.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 727d900ffd5..1aef51bdf50 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -237,6 +237,9 @@ export class RemixAppManager extends PluginEngine { * (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. @@ -265,10 +268,10 @@ class PluginLoader { } set (plugin, actives) { - this.loaders[this.current].set(plugin, actives) + this.currentLoader().set(plugin, actives) } get () { - return this.loaders[this.current].get() + return this.currentLoader().get() } } From a2420476c38c0d61b4367c256603b639658409e4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 7 Jan 2020 10:03:08 +0100 Subject: [PATCH 5/5] standard --- src/remixAppManager.js | 11 +++++------ test-browser/tests/workspace.js | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 1aef51bdf50..0d91fa36b25 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -240,6 +240,7 @@ 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. @@ -250,15 +251,13 @@ class PluginLoader { localStorage.setItem('workspace', JSON.stringify(actives)) } }, - get: () => { - return JSON.parse(localStorage.getItem('workspace')) - } + get: () => { return JSON.parse(localStorage.getItem('workspace')) } } this.loaders['queryParams'] = { set: () => {}, get: () => { - let plugins = queryParams.get()['plugins'] + const { plugins } = queryParams.get() if (!plugins) return [] return plugins.split(',') } @@ -268,10 +267,10 @@ class PluginLoader { } set (plugin, actives) { - this.currentLoader().set(plugin, actives) + this.currentLoader.set(plugin, actives) } get () { - return this.currentLoader().get() + return this.currentLoader.get() } } diff --git a/test-browser/tests/workspace.js b/test-browser/tests/workspace.js index e019f4392be..bf5069c5b5d 100644 --- a/test-browser/tests/workspace.js +++ b/test-browser/tests/workspace.js @@ -1,6 +1,6 @@ 'use strict' -var init = require('../helpers/init') -var sauce = require('./sauce') +const init = require('../helpers/init') +const sauce = require('./sauce') module.exports = { before: function (browser, done) {