Skip to content

feat: keep callback#218

Open
adrian-bueno wants to merge 1 commit intoapache:masterfrom
adrian-bueno:feature/keep-callback
Open

feat: keep callback#218
adrian-bueno wants to merge 1 commit intoapache:masterfrom
adrian-bueno:feature/keep-callback

Conversation

@adrian-bueno
Copy link
Copy Markdown

@adrian-bueno adrian-bueno commented Jan 23, 2022

Platforms affected

  • Electron

Motivation and Context

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:

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

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

Testing

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

  • 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

@adrian-bueno adrian-bueno force-pushed the feature/keep-callback branch from a3b9488 to ed0ca70 Compare August 1, 2024 11:21
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.

1 participant