feat: improve support for plugins code running in main, keeping backward compatibility#238
Open
fabiofabbri84 wants to merge 2 commits into
Open
feat: improve support for plugins code running in main, keeping backward compatibility#238fabiofabbri84 wants to merge 2 commits into
fabiofabbri84 wants to merge 2 commits into
Conversation
…cdv-plugin-exec The goal was to allow passing to the error callback an unaltered copy of the argument, as with the previous implementation you have to throw an exception or return a rejected promise, and this is forwarded to the ipcRenderer.invoke as a string incapsulated in an Error object. See electron/electron#24427 This patch adds a success and error callback parameter for the plugin action, that can be used to implement the action function in a way more coherent with the Cordova architecture, and allowing to bypass the error callback parameter issue. However, for backward compatibility, the action must call the callback parameters before returning (or before fulfilling the returned promise), otherwise it will work as in previous 3.x cordova-electron implementations, calling the success callback with the returned value or calling the error callback with an Error object. Finally, _cdvElectronIPC.exec checks if success and error parameters are actually functions before calling them, in order to avoid annoying error log message if they were not defined.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Description
To fix this, on the main side:
On the renderer side:
Testing
I made demo plugin with cordova-electron 3.x support, based on plugman example. You can find it here: https://github.com/cimatti/cordova-electron-v3-demo-plugin
You can create a demo project using this plugin with these commands:
On the electron app console, you can call the following JavaScript commands to test the problems with the current implementation:
Now you can use these commands to replace cordova-electron 3.1 with my 3.2 proposal:
Calling again the JavaScript console functions above, you can see that backward compatibility is maintained, but calling DemoPlugin.coolMethod omitting callback parameters, you don't get errors.
Now you can test my cordova-electron 3.2 proposal with a plugin supporting it, available at ttps://github.com/cimatti/cordova-electron-v32proposal-demo-plugin
Calling again the JavaScript console functions above, you can see that everything is running as expected
Now you can also test this demo plugin with plain cordova-electron 3.1 to check how is possible to make a plugin compatible with both cordova-electon 3.1 and my proposal for cordova-electron 3.2
Checklist
(platform)if this change only applies to one platform (e.g.(android))