From c59076c4c292883c6d6700e4bd866b5b26f3e8cf Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 6 Jan 2020 17:53:29 +0100 Subject: [PATCH] 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 6df7b03935..0e868a8919 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 5c99f01980..4fbb3f63d2 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() + } +}