Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility for multiple plugin results #247

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

micon4sure
Copy link

@micon4sure micon4sure commented Jan 22, 2023

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

  • 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)
  • 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.

Fixed callback success/error handling
Added test for exception in plugin
@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2023

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           

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants