From 728c260eefaabbf0eea7fe78069c500d193da4bd Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 26 Mar 2018 17:01:43 +0200 Subject: [PATCH 1/4] update use of plugin API --- test-browser/plugin/remix.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test-browser/plugin/remix.js b/test-browser/plugin/remix.js index 5449df96f1..f18bdd648b 100644 --- a/test-browser/plugin/remix.js +++ b/test-browser/plugin/remix.js @@ -8,25 +8,31 @@ window.addEventListener('message', receiveMessage, false) window.onload = function () { document.querySelector('input#testmessageadd').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ + action: 'request', + key: 'editor', type: 'setConfig', - arguments: [document.getElementById('filename').value, document.getElementById('valuetosend').value], + value: [document.getElementById('filename').value, document.getElementById('valuetosend').value], id: 34 - }), 'http://127.0.0.1:8080') + }), '*') }) document.querySelector('input#testmessageremove').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ + action: 'request', + key: 'editor', type: 'removeConfig', - arguments: [document.getElementById('filename').value], + value: [document.getElementById('filename').value], id: 35 - }), 'http://127.0.0.1:8080') + }), '*') }) document.querySelector('input#testmessagerget').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ + action: 'request', + key: 'editor', type: 'getConfig', - arguments: [document.getElementById('filename').value], + value: [document.getElementById('filename').value], id: 36 - }), 'http://127.0.0.1:8080') + }), '*') }) } From 2cfd1ee77e369dbb68ce2ef16c0f8f6047d38d48 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 29 Mar 2018 11:55:24 +0200 Subject: [PATCH 2/4] Update pluginManager.js --- src/app/plugin/pluginManager.js | 86 ++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 9b06e98804..88d68ebc69 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -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": "" * } * + * structure of messages: + * + * - Notification sent by Remix: + *{ + * action: 'notification', + * key: , + * type: , + * value: + *} + * + * - Request sent by the plugin: + *{ + * id: , + * action: 'request', + * key: , + * type: , + * value: + *} + * + * - Response sent by Remix and receive by the plugin: + *{ + * id: , + * action: 'response', + * key: , + * type: , + * value: , + * 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: + * id: , + * action: 'request', + * key: 'config', + * type: 'getConfig', + * value: ['filename.ext'] * } * the plugin will reveice a response like: * { + * id: , + * action: 'response', + * key: 'config', * type: 'getConfig', - * id: * 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) } From 7288f1c17eb9d2acf906cabe31623af341377db9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 16 Apr 2018 12:40:01 +0200 Subject: [PATCH 3/4] data.arguments replaced by data.value --- src/app/plugin/pluginManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 88d68ebc69..6a08bac100 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -143,7 +143,7 @@ class PluginManager { 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) From 3c63421fc90d99dcd6807e6d5608d7ad4f7ff895 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 16 Apr 2018 12:40:14 +0200 Subject: [PATCH 4/4] fix used key --- test-browser/plugin/remix.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test-browser/plugin/remix.js b/test-browser/plugin/remix.js index f18bdd648b..b9984ea646 100644 --- a/test-browser/plugin/remix.js +++ b/test-browser/plugin/remix.js @@ -9,7 +9,7 @@ window.onload = function () { document.querySelector('input#testmessageadd').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ action: 'request', - key: 'editor', + key: 'config', type: 'setConfig', value: [document.getElementById('filename').value, document.getElementById('valuetosend').value], id: 34 @@ -19,7 +19,7 @@ window.onload = function () { document.querySelector('input#testmessageremove').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ action: 'request', - key: 'editor', + key: 'config', type: 'removeConfig', value: [document.getElementById('filename').value], id: 35 @@ -29,7 +29,7 @@ window.onload = function () { document.querySelector('input#testmessagerget').addEventListener('click', function () { window.parent.postMessage(JSON.stringify({ action: 'request', - key: 'editor', + key: 'config', type: 'getConfig', value: [document.getElementById('filename').value], id: 36