From fa5e510bf5a0e5b292110714edfad76ae0a3e19a Mon Sep 17 00:00:00 2001 From: yann300 Date: Sat, 8 Sep 2018 22:05:18 +0200 Subject: [PATCH] support sending data to remix --- src/app/panels/righthand-panel.js | 4 +++- src/app/plugin/pluginAPI.js | 3 +++ src/app/plugin/pluginManager.js | 16 ++++++++++++++++ src/app/tabs/run-tab.js | 13 +++++++++++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index 969d5f5525..0be20ce6f8 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -52,7 +52,9 @@ module.exports = class RighthandPanel { self._deps.fileProviders, self._deps.fileManager, self._deps.udapp - ) + ) + + self._components.registry.put({api: pluginManager, name: 'pluginmanager'}) var analysisTab = new AnalysisTab(self._components.registry) analysisTab.event.register('newStaticAnaysisWarningMessage', (msg, settings) => { self._components.compile.addWarning(msg, settings) }) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 99a738e168..83cd36ff27 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -44,6 +44,9 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => compiler: { getCompilationResult: (mod, cb) => { cb(null, compiler.lastCompilationResult) + }, + sendCompilactionResult: (mod, file, languageVersion, data, cb) => { + pluginManager.receivedDataFrom('sendCompilationResult', mod, file, languageVersion, data) } }, udapp: { diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 6daec2ea64..808da385d8 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -1,4 +1,6 @@ 'use strict' +var remixLib = require('remix-lib') +var EventManager = remixLib.EventManager var executionContext = require('../../execution-context') const PluginAPI = require('./pluginAPI') /** @@ -80,6 +82,7 @@ const PluginAPI = require('./pluginAPI') module.exports = class PluginManager { constructor (app, compiler, txlistener, fileProviders, fileManager, udapp) { const self = this + self.event = new EventManager() var pluginAPI = new PluginAPI( this, fileProviders, @@ -90,6 +93,14 @@ module.exports = class PluginManager { self.plugins = {} self.origins = {} self.inFocus + fileManager.event.register('currentFileChanged', (file, provider) => { + self.broadcast(JSON.stringify({ + action: 'notification', + key: 'editor', + type: 'currentFileChanged', + value: [ file ] + })) + }) compiler.event.register('compilationFinished', (success, data, source) => { self.broadcast(JSON.stringify({ action: 'notification', @@ -184,6 +195,11 @@ module.exports = class PluginManager { this.post(this.origins[origin], value) } } + receivedDataFrom (methodName, mod) { + // TODO check whether 'mod' as right to do that + arguments.shift() + this.event.trigger(methodName, [arguments]) + } post (name, value) { const self = this if (self.plugins[name]) { diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index ed540c2ed4..afa6f87b2d 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -76,7 +76,8 @@ function runTab (opts, localRegistry) { fileManager: self._components.registry.get('filemanager').api, editor: self._components.registry.get('editor').api, logCallback: self._components.registry.get('logCallback').api, - filePanel: self._components.registry.get('filepanel').api + filePanel: self._components.registry.get('filepanel').api, + pluginManager: self._components.registry.get('pluginmanager').api } self._deps.udapp.resetAPI(self._components.transactionContextAPI) self._view.recorderCount = yo`0` @@ -293,7 +294,8 @@ function contractDropdown (events, self) { instanceContainer.appendChild(self._view.noInstancesText) var compFails = yo`` var info = yo`` - self._deps.compiler.event.register('compilationFinished', function (success, data, source) { + + var newlyCompiled = (success, data, source) => { getContractNames(success, data) if (success) { compFails.style.display = 'none' @@ -302,8 +304,15 @@ function contractDropdown (events, self) { compFails.style.display = 'block' document.querySelector(`.${css.contractNames}`).classList.add(css.contractNamesError) } + } + + self._deps.pluginManager.event.register('sendCompilationResult', (mod, file, source, languageVersion, data) => { + // TODO check whether the tab is configured + newlyCompiled(true, data, source) }) + self._deps.compiler.event.register('compilationFinished', newlyCompiled) + var deployAction = (value) => { self._view.createPanel.style.display = value self._view.orLabel.style.display = value