Add paywall state to paywall info #352
Open
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.
Changes in this pull request
Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.ktlintin the main directory and fixed any issues.Greptile Overview
Greptile Summary
This PR adds paywall state persistence by capturing the webview state when a paywall is dismissed. The implementation adds a new
statefield to bothPaywallandPaywallInfomodels, retrieves the state from the webview's JavaScript context viawindow.app.getAllState(), and stores it for later use.Key changes:
state: Map<String, Any>field toPaywallandPaywallInfowith@TransientannotationgetState()suspend function inPaywallMessageHandlerto retrieve state via JavaScript evaluationSetPaywallStateupdate class to handle state updates inPaywallViewStatePaywallView.destroyed()before the paywall is fully dismissedMinor issue found:
getState()usesmainScope.launchinstead ofwithContext(Dispatchers.Main)like otherevaluatecalls in the same file (style consistency)Confidence Score: 4/5
@Transientto avoid serialization issues. State retrieval uses existing JavaScript evaluation infrastructure. Only minor style inconsistency with threading pattern ingetState()function, which doesn't affect functionality but could be improved for consistencyPaywallMessageHandler.kt- consider aligning the threading pattern ingetState()with otherevaluatecalls in the fileImportant Files Changed
statefield to store paywall state with proper serialization annotationgetState()function to retrieve state via JavaScript; minor threading pattern inconsistencySequence Diagram
sequenceDiagram participant PV as PaywallView participant PMH as PaywallMessageHandler participant WV as WebView participant Controller as PaywallViewController participant Paywall as Paywall Model Note over PV: Paywall is being dismissed PV->>PV: "destroyed()" PV->>PMH: "getState()" Note over PMH: Suspend function to get state PMH->>PMH: "mainScope.launch" PMH->>WV: "evaluate(window.app.getAllState())" WV-->>PMH: "JavaScript result (JSON string)" alt Valid JSON result PMH->>PMH: "parseToJsonElement(result)" PMH->>PMH: "jsonElementToMap(parsed)" PMH-->>PV: "Map<String, Any>" else Null or Parse Error PMH-->>PV: "emptyMap()" end PV->>Controller: "updateState(SetPaywallState(paywallState))" Controller->>Paywall: "copy(state = paywallState)" Note over PV,Paywall: State preserved for PaywallInfo PV->>PV: "trackClose()"