Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin API #1196

Merged
merged 5 commits into from
Apr 19, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update pluginManager.js
  • Loading branch information
yann300 committed Apr 10, 2018
commit 2cfd1ee77e369dbb68ce2ef16c0f8f6047d38d48
86 changes: 68 additions & 18 deletions src/app/plugin/pluginManager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
'use strict'
/**
* Register and Manage plugin:
*
* Plugin registration is done in the settings tab,
* using the following format:
* {
* "title": "<plugin name>",
* "url": "<plugin url>"
* }
*
* structure of messages:
*
* - Notification sent by Remix:
*{
* action: 'notification',
* key: <string>,
* type: <string>,
* value: <array>
*}
*
* - Request sent by the plugin:
*{
* id: <number>,
* action: 'request',
* key: <string>,
* type: <string>,
* value: <array>
*}
*
* - Response sent by Remix and receive by the plugin:
*{
* id: <number>,
* action: 'response',
* key: <string>,
* type: <string>,
* value: <array>,
* error: (see below)
*}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked again: https://github.com/ethereum/remix-ide/issues/1156

  • The original proposal is var { id, status, type, key, value } = msg
  • You said you would like to add the action field to indicate "response/notification/request".
  • That would make it var { action, id, status, type, key, value } = msg
  • But now the status is/was renamed to error i guess.

Just to make sure how i have to think about it :-)
So i guess we now have: var { action, id, error: status, type, key, value } = msg

I would say that is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above comment is just for me to clarify.
If this is how it's meant, i would say the PR looks good to me :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes except that error is undefined if there's no error

* => The `error` property is `undefined` if no error happened.
* => In case of error (due to permission, system error, API error, etc...):
* error: { code, msg (optional), data (optional), stack (optional)
* => possible error code are still to be defined, but the generic one would be 500.
*
* Plugin receive 4 types of message:
* - focus (when he get focus)
* - unfocus (when he loose focus - is hidden)
Expand All @@ -19,16 +53,20 @@
* CONFIG:
* - getConfig(filename). The data to send should be formatted like:
* {
* type: 'getConfig',
* arguments: ['filename.ext'],
* id: <requestid>
* id: <requestid>,
* action: 'request',
* key: 'config',
* type: 'getConfig',
* value: ['filename.ext']
* }
* the plugin will reveice a response like:
* {
* id: <requestid>,
* action: 'response',
* key: 'config',
* type: 'getConfig',
* id: <requestid>
* error,
* result
* value: ['content of filename.ext']
* }
* same apply for the other call
* - setConfig(filename, content)
Expand All @@ -47,12 +85,14 @@ class PluginManager {
if (this.inFocus) {
// trigger to the current focus
this.post(this.inFocus, JSON.stringify({
action: 'notification',
key: 'compiler',
type: 'compilationFinished',
value: {
success: success,
data: data,
source: source
}
value: [
success,
data,
source
]
}))
}
})
Expand All @@ -61,37 +101,47 @@ class PluginManager {
if (this.inFocus && this.inFocus !== tabName) {
// trigger unfocus
this.post(this.inFocus, JSON.stringify({
type: 'unfocus'
action: 'notification',
key: 'app',
type: 'unfocus',
value: []
}))
}
if (this.plugins[tabName]) {
// trigger focus
this.post(tabName, JSON.stringify({
type: 'focus'
action: 'notification',
key: 'app',
type: 'focus',
value: []
}))
this.inFocus = tabName
this.post(tabName, JSON.stringify({
action: 'notification',
key: 'compiler',
type: 'compilationData',
value: api.compiler.getCompilationResult()
value: [api.compiler.getCompilationResult()]
}))
}
})

window.addEventListener('message', (event) => {
function response (type, callid, error, result) {
function response (key, type, callid, error, result) {
self.post(self.inFocus, JSON.stringify({
id: callid,
action: 'response',
key: key,
type: type,
error: error,
result: result
value: [ result ]
}))
}
if (event.type === 'message' && this.inFocus && this.plugins[this.inFocus] && this.plugins[this.inFocus].origin === event.origin) {
var data = JSON.parse(event.data)
data.arguments.unshift(this.inFocus)
data.value.unshift(this.inFocus)
if (allowedapi[data.type]) {
data.arguments.push((error, result) => {
response(data.type, data.id, error, result)
data.value.push((error, result) => {
response(data.key, data.type, data.id, error, result)
})
api[data.key][data.type].apply({}, data.arguments)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data.arguments should be data.value

}
Expand Down