-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update plugin API #1196
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update pluginManager.js
- Loading branch information
commit 2cfd1ee77e369dbb68ce2ef16c0f8f6047d38d48
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
*} | ||
* => 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) | ||
|
@@ -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) | ||
|
@@ -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 | ||
] | ||
})) | ||
} | ||
}) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
var { id, status, type, key, value } = msg
action
field to indicate "response/notification/request".var { action, id, status, type, key, value } = msg
status
is/was renamed toerror
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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