Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
✨ feat: resolve dangling startScan in stopScan (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
tafelnl committed Jun 30, 2021
1 parent f7cf711 commit 874466c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 5 additions & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface BarcodeScannerPlugin {
hideBackground(): Promise<void>;
showBackground(): Promise<void>;
startScan(options?: ScanOptions): Promise<ScanResult>;
stopScan(): Promise<void>;
stopScan(options?: StopScanOptions): Promise<void>;
checkPermission(
options?: CheckPermissionOptions,
): Promise<CheckPermissionResult>;
Expand Down Expand Up @@ -39,6 +39,10 @@ export interface ScanOptions {
targetedFormats?: SupportedFormat[];
}

export interface StopScanOptions {
resolveScan?: boolean;
}

export interface ScanResult {
hasContent: boolean;
content?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ScanResult,
CheckPermissionOptions,
CheckPermissionResult,
StopScanOptions,
} from './definitions';

export class BarcodeScannerWeb
Expand All @@ -27,7 +28,7 @@ export class BarcodeScannerWeb
throw this.unimplemented('Not implemented on web.');
}

async stopScan(): Promise<void> {
async stopScan(_options?: StopScanOptions): Promise<void> {
throw this.unimplemented('Not implemented on web.');
}

Expand Down

0 comments on commit 874466c

Please sign in to comment.