feat: add basic eager initialization #124
Draft
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.
Fixes #121.
Android implementation by @ahsanz024. iOS implementation by @SwenHutop. We use this at @ClarkSource for our new Capacitor app.
The code is structured rather weirdly, because we tried to apply the changes as a patch on top of the existing
cordova_sdkchanging only as little upstream code as necessary, to make merging updates back in easier.How does it work?
Explaining for Android, because I understand that implementation best, but it's basically the same for iOS.
COMMAND_SET_*_CALLBACKhandlers and registerBufferedCallbackContexts for all of them.COMMAND_CREATEand pass along our desired confifuration.Adjustplugin, it does not callAdjust.create(config), as we already did that from the native side.onAttributionChanged, gets triggered, it will find aBufferedCallbackContextand callsendPluginResult(pluginResult)on it, as if it was a regularPluginResult.BufferedCallbackContextstores all calls tosendPluginResult(pluginResult).Adjust.setAttributionCallback(cb), theBufferedCallbackContextwill replay all calls tosendPluginResult(pluginResult)on the new "real"PluginResult. TheBufferedCallbackContextis then destroyed and replaced by the newPluginResult, so that further callbacks are routed directly to JS, as if everything was normal.The following would be left to do to make this mergeable:
EagerAdjustCordovaback intoAdjustCordova.AdjustConfigto be used for eager initialization..jsonfile would be nice, I guess. Otherwise using an imperative call from the native code would be nice as well.AdjustConfigis present or the eager initialization call was made.Adjust.create(config)then.set*Callback(cb)methods when in eager mode.