diff --git a/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java b/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java index 878397e..854f07d 100644 --- a/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java +++ b/android/src/main/java/com/dutchconcepts/capacitor/barcodescanner/BarcodeScanner.java @@ -329,6 +329,15 @@ public void startScan(PluginCall call) { @PluginMethod public void stopScan(PluginCall call) { + if (call.hasOption("resolveScan") && call.getBool("resolveScan") && getSavedCall() != null) { + JSObject jsObject = new JSObject(); + jsObject.put("hasContent", false); + + if (getSavedCall() != null) { + getSavedCall().resolve(jsObject); + } + } + destroy(); call.resolve(); } diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 5a3cc06..8cfaefd 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -373,6 +373,14 @@ public class BarcodeScanner: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate { } @objc func stopScan(_ call: CAPPluginCall) { + if (call.hasOption("resolveScan") && call.getBool("resolveScan") && self.savedCall != nil) { + var jsObject = PluginResultData() + jsObject["hasContent"] = false + + savedCall.resolve(jsObject) + savedCall = nil + } + self.destroy() call.resolve() } diff --git a/src/definitions.ts b/src/definitions.ts index c65ee89..6a5d55b 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -3,7 +3,7 @@ export interface BarcodeScannerPlugin { hideBackground(): Promise; showBackground(): Promise; startScan(options?: ScanOptions): Promise; - stopScan(): Promise; + stopScan(options?: StopScanOptions): Promise; checkPermission( options?: CheckPermissionOptions, ): Promise; @@ -39,6 +39,10 @@ export interface ScanOptions { targetedFormats?: SupportedFormat[]; } +export interface StopScanOptions { + resolveScan?: boolean; +} + export interface ScanResult { hasContent: boolean; content?: string; diff --git a/src/web.ts b/src/web.ts index 14fc836..f3c7ecc 100644 --- a/src/web.ts +++ b/src/web.ts @@ -6,6 +6,7 @@ import type { ScanResult, CheckPermissionOptions, CheckPermissionResult, + StopScanOptions, } from './definitions'; export class BarcodeScannerWeb @@ -27,7 +28,7 @@ export class BarcodeScannerWeb throw this.unimplemented('Not implemented on web.'); } - async stopScan(): Promise { + async stopScan(_options?: StopScanOptions): Promise { throw this.unimplemented('Not implemented on web.'); }