Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
1cff4b7c
Unverified
Commit
1cff4b7c
authored
Apr 19, 2018
by
yann300
Committed by
GitHub
Apr 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1196 from ethereum/updatepmluginAPI
Update plugin API
parents
ead2d658
68d370f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
20 deletions
+76
-20
pluginManager.js
src/app/plugin/pluginManager.js
+64
-14
remix.js
test-browser/plugin/remix.js
+12
-6
No files found.
src/app/plugin/pluginManager.js
View file @
1cff4b7c
'use strict'
'use strict'
/**
/**
* Register and Manage plugin:
* Register and Manage plugin:
*
* Plugin registration is done in the settings tab,
* Plugin registration is done in the settings tab,
* using the following format:
* using the following format:
* {
* {
...
@@ -8,6 +9,39 @@
...
@@ -8,6 +9,39 @@
* "url": "<plugin url>"
* "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:
* Plugin receive 4 types of message:
* - focus (when he get focus)
* - focus (when he get focus)
* - unfocus (when he loose focus - is hidden)
* - unfocus (when he loose focus - is hidden)
...
@@ -19,16 +53,20 @@
...
@@ -19,16 +53,20 @@
* CONFIG:
* CONFIG:
* - getConfig(filename). The data to send should be formatted like:
* - getConfig(filename). The data to send should be formatted like:
* {
* {
* id: <requestid>,
* action: 'request',
* key: 'config',
* type: 'getConfig',
* type: 'getConfig',
* arguments: ['filename.ext'],
* value: ['filename.ext']
* id: <requestid>
* }
* }
* the plugin will reveice a response like:
* the plugin will reveice a response like:
* {
* {
* id: <requestid>,
* action: 'response',
* key: 'config',
* type: 'getConfig',
* type: 'getConfig',
* id: <requestid>
* error,
* error,
*
result
*
value: ['content of filename.ext']
* }
* }
* same apply for the other call
* same apply for the other call
* - setConfig(filename, content)
* - setConfig(filename, content)
...
@@ -50,8 +88,10 @@ module.exports = class PluginManager {
...
@@ -50,8 +88,10 @@ module.exports = class PluginManager {
if
(
self
.
inFocus
)
{
if
(
self
.
inFocus
)
{
// trigger to the current focus
// trigger to the current focus
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
action
:
'notification'
,
key
:
'compiler'
,
type
:
'compilationFinished'
,
type
:
'compilationFinished'
,
value
:
{
success
,
data
,
source
}
value
:
[
success
,
data
,
source
]
}))
}))
}
}
})
})
...
@@ -60,39 +100,49 @@ module.exports = class PluginManager {
...
@@ -60,39 +100,49 @@ module.exports = class PluginManager {
if
(
self
.
inFocus
&&
self
.
inFocus
!==
tabName
)
{
if
(
self
.
inFocus
&&
self
.
inFocus
!==
tabName
)
{
// trigger unfocus
// trigger unfocus
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
type
:
'unfocus'
action
:
'notification'
,
key
:
'app'
,
type
:
'unfocus'
,
value
:
[]
}))
}))
}
}
if
(
self
.
plugins
[
tabName
])
{
if
(
self
.
plugins
[
tabName
])
{
// trigger focus
// trigger focus
self
.
post
(
tabName
,
JSON
.
stringify
({
self
.
post
(
tabName
,
JSON
.
stringify
({
type
:
'focus'
action
:
'notification'
,
key
:
'app'
,
type
:
'focus'
,
value
:
[]
}))
}))
self
.
inFocus
=
tabName
self
.
inFocus
=
tabName
self
.
post
(
tabName
,
JSON
.
stringify
({
self
.
post
(
tabName
,
JSON
.
stringify
({
action
:
'notification'
,
key
:
'compiler'
,
type
:
'compilationData'
,
type
:
'compilationData'
,
value
:
api
.
compiler
.
getCompilationResult
()
value
:
[
api
.
compiler
.
getCompilationResult
()]
}))
}))
}
}
})
})
window
.
addEventListener
(
'message'
,
(
event
)
=>
{
window
.
addEventListener
(
'message'
,
(
event
)
=>
{
function
response
(
type
,
callid
,
error
,
result
)
{
function
response
(
key
,
type
,
callid
,
error
,
result
)
{
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
self
.
post
(
self
.
inFocus
,
JSON
.
stringify
({
id
:
callid
,
id
:
callid
,
action
:
'response'
,
key
:
key
,
type
:
type
,
type
:
type
,
error
:
error
,
error
:
error
,
result
:
result
value
:
[
result
]
}))
}))
}
}
if
(
event
.
type
===
'message'
&&
self
.
inFocus
&&
self
.
plugins
[
self
.
inFocus
]
&&
self
.
plugins
[
self
.
inFocus
].
origin
===
event
.
origin
)
{
if
(
event
.
type
===
'message'
&&
self
.
inFocus
&&
self
.
plugins
[
self
.
inFocus
]
&&
self
.
plugins
[
self
.
inFocus
].
origin
===
event
.
origin
)
{
var
data
=
JSON
.
parse
(
event
.
data
)
var
data
=
JSON
.
parse
(
event
.
data
)
data
.
arguments
.
unshift
(
self
.
inFocus
)
data
.
value
.
unshift
(
self
.
inFocus
)
if
(
self
.
allowedapi
[
data
.
type
])
{
if
(
self
.
allowedapi
[
data
.
type
])
{
data
.
arguments
.
push
((
error
,
result
)
=>
{
data
.
value
.
push
((
error
,
result
)
=>
{
response
(
data
.
type
,
data
.
id
,
error
,
result
)
response
(
data
.
key
,
data
.
type
,
data
.
id
,
error
,
result
)
})
})
api
[
data
.
key
][
data
.
type
].
apply
({},
data
.
arguments
)
api
[
data
.
key
][
data
.
type
].
apply
({},
data
.
value
)
}
}
}
}
},
false
)
},
false
)
...
...
test-browser/plugin/remix.js
View file @
1cff4b7c
...
@@ -8,25 +8,31 @@ window.addEventListener('message', receiveMessage, false)
...
@@ -8,25 +8,31 @@ window.addEventListener('message', receiveMessage, false)
window
.
onload
=
function
()
{
window
.
onload
=
function
()
{
document
.
querySelector
(
'input#testmessageadd'
).
addEventListener
(
'click'
,
function
()
{
document
.
querySelector
(
'input#testmessageadd'
).
addEventListener
(
'click'
,
function
()
{
window
.
parent
.
postMessage
(
JSON
.
stringify
({
window
.
parent
.
postMessage
(
JSON
.
stringify
({
action
:
'request'
,
key
:
'config'
,
type
:
'setConfig'
,
type
:
'setConfig'
,
arguments
:
[
document
.
getElementById
(
'filename'
).
value
,
document
.
getElementById
(
'valuetosend'
).
value
],
value
:
[
document
.
getElementById
(
'filename'
).
value
,
document
.
getElementById
(
'valuetosend'
).
value
],
id
:
34
id
:
34
}),
'
http://127.0.0.1:8080
'
)
}),
'
*
'
)
})
})
document
.
querySelector
(
'input#testmessageremove'
).
addEventListener
(
'click'
,
function
()
{
document
.
querySelector
(
'input#testmessageremove'
).
addEventListener
(
'click'
,
function
()
{
window
.
parent
.
postMessage
(
JSON
.
stringify
({
window
.
parent
.
postMessage
(
JSON
.
stringify
({
action
:
'request'
,
key
:
'config'
,
type
:
'removeConfig'
,
type
:
'removeConfig'
,
arguments
:
[
document
.
getElementById
(
'filename'
).
value
],
value
:
[
document
.
getElementById
(
'filename'
).
value
],
id
:
35
id
:
35
}),
'
http://127.0.0.1:8080
'
)
}),
'
*
'
)
})
})
document
.
querySelector
(
'input#testmessagerget'
).
addEventListener
(
'click'
,
function
()
{
document
.
querySelector
(
'input#testmessagerget'
).
addEventListener
(
'click'
,
function
()
{
window
.
parent
.
postMessage
(
JSON
.
stringify
({
window
.
parent
.
postMessage
(
JSON
.
stringify
({
action
:
'request'
,
key
:
'config'
,
type
:
'getConfig'
,
type
:
'getConfig'
,
arguments
:
[
document
.
getElementById
(
'filename'
).
value
],
value
:
[
document
.
getElementById
(
'filename'
).
value
],
id
:
36
id
:
36
}),
'
http://127.0.0.1:8080
'
)
}),
'
*
'
)
})
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment