adrian-bueno opened a new pull request #218: URL: https://github.com/apache/cordova-electron/pull/218
<!-- Please make sure the checklist boxes are all checked before submitting the PR. The checklist is intended as a quick reference, for complete details please see our Contributor Guidelines: http://cordova.apache.org/contribute/contribute_guidelines.html Thanks! --> ### Platforms affected - Electron ### Motivation and Context <!-- Why is this change required? What problem does it solve? --> <!-- If it fixes an open issue, please link to the issue here. --> Android and iOS plugins have a "keep callback" option that let us send multiple responses like an observable. In Electron this feature doesn't exist yet. Android plugin example: ```java final PluginResult result = new PluginResult(PluginResult.Status.OK, "Hello"); result.setKeepCallback(true); callbackContext.sendPluginResult(result); ``` I found this problem when I tried to build a plugin that sends events when a USB is connected/disconnected. ### Description <!-- Describe your changes in detail --> I tried to find a solution that doesn't break existing plugins, and decided to add a new **exec$** method. The **$** is used to identify which functions could return multiple values. The **exec$** method, instead of using `ipcRenderer.invoke()`, uses `ipcRenderer.on()` and `ipcRenderer.send()` with a new channel `cdv-plugin-exec$`. To identify requests, a unique ID is used `Date.now() + Math.random()` (this should be random enough). #### Also fixed Electron version I have also fixed Electron versión in package.json (removed ^ from "^14.0.0"), because when dependencies with C/C++ code are used, these dependencies are rebuild using Electron 14.2.1 but the code is run with Electron 14.0.0. For example, I am using the following dependencies in a private plugin: - https://github.com/serialport/node-serialport - https://github.com/node-usb/node-usb And this error appears: > Error invoking remote method 'cdv-plugin-exec': Error: The module '...../cordova-plugin-xxx/src/electron/node_modules/@serialport/bindings/build/Release/bindings.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 89. This version of Node.js requires NODE_MODULE_VERSION 97. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). But after fixing Electron version to 14.0.0, they work fine. The version 14.0.0 is also already fixed in `lib/build/base.json`. ### Testing <!-- Please describe in detail how you tested your changes. --> I have run `npm run test`. I have also added an example in this plugin `tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample`. I don't know if there is currently a way to automatically test code inside path `tests/spec/fixtures`. ### Checklist - [x] I've run the tests to see all new and existing tests pass - [ ] I added automated test coverage as appropriate for this change - [ ] Commit is prefixed with `(platform)` if this change only applies to one platform (e.g. `(android)`) - [ ] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/)) - [ ] I've updated the documentation if necessary -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
