|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
'use strict' |
|
|
|
|
/** |
|
|
|
|
* Register and Manage plugin: |
|
|
|
|
* |
|
|
|
|
* Plugin registration is done in the settings tab, |
|
|
|
|
* using the following format: |
|
|
|
|
* { |
|
|
|
@ -8,6 +9,39 @@ |
|
|
|
|
* "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) |
|
|
|
@ -50,8 +88,10 @@ module.exports = class PluginManager { |
|
|
|
|
if (self.inFocus) { |
|
|
|
|
// trigger to the current focus
|
|
|
|
|
self.post(self.inFocus, JSON.stringify({ |
|
|
|
|
action: 'notification', |
|
|
|
|
key: 'compiler', |
|
|
|
|
type: 'compilationFinished', |
|
|
|
|
value: { success, data, source } |
|
|
|
|
value: [ success, data, source ] |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -60,39 +100,49 @@ module.exports = class PluginManager { |
|
|
|
|
if (self.inFocus && self.inFocus !== tabName) { |
|
|
|
|
// trigger unfocus
|
|
|
|
|
self.post(self.inFocus, JSON.stringify({ |
|
|
|
|
type: 'unfocus' |
|
|
|
|
action: 'notification', |
|
|
|
|
key: 'app', |
|
|
|
|
type: 'unfocus', |
|
|
|
|
value: [] |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
if (self.plugins[tabName]) { |
|
|
|
|
// trigger focus
|
|
|
|
|
self.post(tabName, JSON.stringify({ |
|
|
|
|
type: 'focus' |
|
|
|
|
action: 'notification', |
|
|
|
|
key: 'app', |
|
|
|
|
type: 'focus', |
|
|
|
|
value: [] |
|
|
|
|
})) |
|
|
|
|
self.inFocus = tabName |
|
|
|
|
self.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' && self.inFocus && self.plugins[self.inFocus] && self.plugins[self.inFocus].origin === event.origin) { |
|
|
|
|
var data = JSON.parse(event.data) |
|
|
|
|
data.arguments.unshift(self.inFocus) |
|
|
|
|
data.value.unshift(self.inFocus) |
|
|
|
|
if (self.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) |
|
|
|
|
api[data.key][data.type].apply({}, data.value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, false) |
|
|
|
|