cordova-electron icon indicating copy to clipboard operation
cordova-electron copied to clipboard

Added possibility for multiple plugin results

Open micon4sure opened this issue 2 years ago • 1 comments

Platforms affected

  • electron
  • browser

Motivation and Context

It is currently not possible to send more than one plugin response per service action call. This is not ideal in situations where a native process might generate more than one result over time. Additionally, the API is more in line with that of cordova-android and from what I can gather also cordova-ios

Description

Related to Allow for multiple plugin results #248 The version in this branch creates a callbackId in exec.js and passes it on to preload. preload registers this callbackId with ipcRenderer and invokes the callback. main creates a CallbackContext with this callbackId and passes it on to the service action dispatch service actions now have a similar API as android: (action: string, args: any, callbackContext: Object)

callbackContext provides functions success and error. Additionally, it exposes the PluginResult class along with sendPluginResult. This makes it possible to send multiple results when keepCallback is set to true. There might be a better way to provide this API to plugins.

Testing

I used document.addEventListener in the plugin sample to call a demo implementation of the new api

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
  • [x] Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • [x] 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)
  • [x] I've updated the documentation if necessary

Additional notes

  • ~~The API changes would break existing plugins but it would be possible to load the plugin package.json and check for an API flag. The old API would be considered deprecated until at least 5.0~~ API flag implemented in 198cf24
  • I couldn't get the browser fallback to work so couldn't test for that.

micon4sure avatar Jan 22 '23 01:01 micon4sure

Codecov Report

Merging #247 (198cf24) into master (7053f35) will not change coverage. The diff coverage is n/a.

@@            Coverage Diff            @@
##            master      #247   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        14           
  Lines          656       656           
=========================================
  Hits           656       656           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Jan 22 '23 14:01 codecov-commenter