| Index: extensions/renderer/resources/serial_custom_bindings.js
|
| diff --git a/extensions/renderer/resources/serial_custom_bindings.js b/extensions/renderer/resources/serial_custom_bindings.js
|
| index 3d15acff1c7fca3f4a1e9420bc53a5fd8162414e..cf1660733cccac0e9432bdb853140e9f3125bf76 100644
|
| --- a/extensions/renderer/resources/serial_custom_bindings.js
|
| +++ b/extensions/renderer/resources/serial_custom_bindings.js
|
| @@ -12,19 +12,64 @@ function createAsyncProxy(targetPromise, functionNames) {
|
| return targetPromise.then(function(target) {
|
| return $Function.apply(target[name], target, args);
|
| });
|
| - }
|
| + };
|
| });
|
| return functionProxies;
|
| }
|
|
|
| var serialService = createAsyncProxy(requireAsync('serial_service'), [
|
| 'getDevices',
|
| + 'createConnection',
|
| + 'getConnection',
|
| + 'getConnections',
|
| ]);
|
|
|
| +function forwardToConnection(methodName) {
|
| + return function(connectionId) {
|
| + var args = $Array.slice(arguments, 1);
|
| + return serialService.getConnection(connectionId).then(function(connection) {
|
| + return $Function.apply(connection[methodName], connection, args);
|
| + });
|
| + };
|
| +}
|
| +
|
| binding.registerCustomHook(function(bindingsAPI) {
|
| var apiFunctions = bindingsAPI.apiFunctions;
|
| apiFunctions.setHandleRequestWithPromise('getDevices',
|
| serialService.getDevices);
|
| +
|
| + apiFunctions.setHandleRequestWithPromise('connect', function(path, options) {
|
| + return serialService.createConnection(path, options).then(function(result) {
|
| + return result.info;
|
| + }).catch (function(e) {
|
| + throw new Error('Failed to connect to the port.');
|
| + });
|
| + });
|
| +
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'disconnect', forwardToConnection('close'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'getInfo', forwardToConnection('getInfo'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'update', forwardToConnection('setOptions'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'getControlSignals', forwardToConnection('getControlSignals'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'setControlSignals', forwardToConnection('setControlSignals'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'flush', forwardToConnection('flush'));
|
| + apiFunctions.setHandleRequestWithPromise(
|
| + 'setPaused', forwardToConnection('setPaused'));
|
| +
|
| + apiFunctions.setHandleRequestWithPromise('getConnections', function() {
|
| + return serialService.getConnections().then(function(connections) {
|
| + var promises = [];
|
| + for (var id in connections) {
|
| + promises.push(connections[id].getInfo());
|
| + }
|
| + return Promise.all(promises);
|
| + });
|
| + });
|
| });
|
|
|
| exports.binding = binding.generate();
|
|
|