fix(barcode-scanner): settle the pending scan() promise on cancel (fix #3560) - #3571
Open
ghostshreyash wants to merge 1 commit into
Open
fix(barcode-scanner): settle the pending scan() promise on cancel (fix #3560)#3571ghostshreyash wants to merge 1 commit into
ghostshreyash wants to merge 1 commit into
Conversation
…tauri-apps#3560) On Android, cancel() called destroy() first, and destroy() sets savedInvoke to null, so the savedInvoke?.reject("cancelled") that follows was a no-op. The pending scan() promise was never settled and callers awaiting it were stranded, which is especially bad in windowed mode where the page background stays transparent. Reject the pending invoke before tearing the camera down, matching the order the iOS implementation already uses.
Contributor
Package Changes Through 4f483e4There are 4 changes which include barcode-scanner with patch, barcode-scanner-js with patch, http with patch, http-js with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #3560.
Bug
On Android,
cancel()tore the camera down but never settled the pendingscan()promise. InBarcodeScannerPlugin.kt,cancel()calleddestroy()first, anddestroy()setssavedInvoke = null, so the followingsavedInvoke?.reject("cancelled")was a no-op. Frontend code awaitingscan()was stranded forever, which is especially bad in windowed mode where the page background stays transparent.Fix
Reject the pending invoke before calling
destroy(). This is the order the iOS implementation already uses (self.invoke?.reject("cancelled")thendestroy()), so both platforms now behave the same:scan()rejects with"cancelled", andcancel()itself resolves.Verification
Built
examples/apifor Android (x86_64, debug) and ran it on an Android 16 / API 36 emulator, the same API level as in the report. Scanner view, Scan, then Cancel:cancelled, which is the example's owncancelScan()message. Thescan()promise never settled, so its.catchnever ran.{ "message": "cancelled" }fromscan().catch(...)followed bycancelled. The camera is released in both cases.Changeset added for
barcode-scannerandbarcode-scanner-js(patch).