load workspace from localstorage or queryparams

pull/1/head
yann300 5 years ago
parent 8dcf0057c2
commit 62a43de74f
  1. 2
      src/app.js
  2. 46
      src/remixAppManager.js

@ -208,7 +208,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// APP_MANAGER // APP_MANAGER
const appManager = new RemixAppManager({}) const appManager = new RemixAppManager({})
const workspace = JSON.parse(localStorage.getItem('workspace')) const workspace = appManager.pluginLoader.get()
// SERVICES // SERVICES
// ----------------- import content servive ---------------------------- // ----------------- import content servive ----------------------------

@ -2,6 +2,7 @@
import { PluginEngine, IframePlugin } from '@remixproject/engine' import { PluginEngine, IframePlugin } from '@remixproject/engine'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { PermissionHandler } from './app/ui/persmission-handler' import { PermissionHandler } from './app/ui/persmission-handler'
import QueryParams from './lib/query-params'
const requiredModules = [ // services + layout views + system views const requiredModules = [ // services + layout views + system views
'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport',
@ -19,15 +20,13 @@ export class RemixAppManager extends PluginEngine {
constructor (plugins) { constructor (plugins) {
super(plugins, settings) super(plugins, settings)
this.event = new EventEmitter() this.event = new EventEmitter()
this.donotAutoReload = ['remixd'] // that would be a bad practice to force loading some plugins at page load.
this.registered = {} this.registered = {}
this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/profile.json' this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/profile.json'
this.pluginLoader = new PluginLoader()
} }
onActivated (plugin) { onActivated (plugin) {
if (!this.donotAutoReload.includes(plugin.name)) { this.pluginLoader.set(plugin, this.actives)
localStorage.setItem('workspace', JSON.stringify(this.actives))
}
this.event.emit('activate', plugin.name) this.event.emit('activate', plugin.name)
} }
@ -46,7 +45,7 @@ export class RemixAppManager extends PluginEngine {
} }
onDeactivated (plugin) { onDeactivated (plugin) {
localStorage.setItem('workspace', JSON.stringify(this.actives)) this.pluginLoader.set(plugin, this.actives)
this.event.emit('deactivate', plugin.name) 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()
}
}

Loading…
Cancel
Save