Skip to content

Commit

Permalink
load workspace from localstorage or queryparams
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Jan 6, 2020
1 parent 8dcf005 commit 62a43de
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------
Expand Down
46 changes: 41 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,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()
}
}

0 comments on commit 62a43de

Please sign in to comment.