Committed by
Ryan Duffy
Update macos/Classes/MobileScannerPlugin.swift
Co-authored-by: Navaron Bracke <brackenavaron@gmail.com> Update macos/Classes/MobileScannerPlugin.swift Co-authored-by: Navaron Bracke <brackenavaron@gmail.com> Update macos/Classes/MobileScannerPlugin.swift Co-authored-by: Navaron Bracke <brackenavaron@gmail.com> recommended fixes
Showing
1 changed file
with
8 additions
and
8 deletions
| @@ -112,7 +112,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -112,7 +112,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 112 | registry.textureFrameAvailable(textureId) | 112 | registry.textureFrameAvailable(textureId) |
| 113 | 113 | ||
| 114 | let currentTime = Date().timeIntervalSince1970 | 114 | let currentTime = Date().timeIntervalSince1970 |
| 115 | - let eligibleForScan = currentTime > nextScanTime && imagesCurrentlyBeingProcessed == false | 115 | + let eligibleForScan = currentTime > nextScanTime && !imagesCurrentlyBeingProcessed |
| 116 | if ((detectionSpeed == DetectionSpeed.normal || detectionSpeed == DetectionSpeed.noDuplicates) && eligibleForScan || detectionSpeed == DetectionSpeed.unrestricted) { | 116 | if ((detectionSpeed == DetectionSpeed.normal || detectionSpeed == DetectionSpeed.noDuplicates) && eligibleForScan || detectionSpeed == DetectionSpeed.unrestricted) { |
| 117 | nextScanTime = currentTime + timeoutSeconds | 117 | nextScanTime = currentTime + timeoutSeconds |
| 118 | imagesCurrentlyBeingProcessed = true | 118 | imagesCurrentlyBeingProcessed = true |
| @@ -130,8 +130,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -130,8 +130,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 130 | if let results = request.results as? [VNBarcodeObservation] { | 130 | if let results = request.results as? [VNBarcodeObservation] { |
| 131 | for barcode in results { | 131 | for barcode in results { |
| 132 | if self?.scanWindow != nil && cgImage != nil { | 132 | if self?.scanWindow != nil && cgImage != nil { |
| 133 | - let match = self?.isbarCodeInScanWindow(self!.scanWindow!, barcode, cgImage!) | ||
| 134 | - if (match == false) { | 133 | + let match = self?.isBarCodeInScanWindow(self!.scanWindow!, barcode, cgImage!) ?? false |
| 134 | + if (!match) { | ||
| 135 | continue | 135 | continue |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| @@ -147,7 +147,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -147,7 +147,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | } else { | 149 | } else { |
| 150 | - print(error!.localizedDescription) | 150 | + self?.sink?(FlutterError(code: "MobileScanner", message: error?.localizedDescription, details: nil)) |
| 151 | } | 151 | } |
| 152 | }) | 152 | }) |
| 153 | if(self?.symbologies.isEmpty == false){ | 153 | if(self?.symbologies.isEmpty == false){ |
| @@ -155,8 +155,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -155,8 +155,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 155 | barcodeRequest.symbologies = self!.symbologies | 155 | barcodeRequest.symbologies = self!.symbologies |
| 156 | } | 156 | } |
| 157 | try imageRequestHandler.perform([barcodeRequest]) | 157 | try imageRequestHandler.perform([barcodeRequest]) |
| 158 | - } catch { | ||
| 159 | - print(error) | 158 | + } catch let e { |
| 159 | + self?.sink?(FlutterError(code: "MobileScanner", message: e.localizedDescription, details: nil)) | ||
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
| @@ -203,7 +203,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -203,7 +203,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 203 | scanWindow = CGRect(x: minX, y: minY, width: width, height: height) | 203 | scanWindow = CGRect(x: minX, y: minY, width: width, height: height) |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | - func isbarCodeInScanWindow(_ scanWindow: CGRect, _ barcode: VNBarcodeObservation, _ inputImage: CGImage) -> Bool { | 206 | + func isBarCodeInScanWindow(_ scanWindow: CGRect, _ barcode: VNBarcodeObservation, _ inputImage: CGImage) -> Bool { |
| 207 | 207 | ||
| 208 | let imageWidth = CGFloat(inputImage.width); | 208 | let imageWidth = CGFloat(inputImage.width); |
| 209 | let imageHeight = CGFloat(inputImage.height); | 209 | let imageHeight = CGFloat(inputImage.height); |
| @@ -217,7 +217,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | @@ -217,7 +217,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | ||
| 217 | return scaledScanWindow.contains(barcode.boundingBox) | 217 | return scaledScanWindow.contains(barcode.boundingBox) |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | - func isbarCodeInScanWindow(_ scanWindow: CGRect, _ barcode: VNBarcodeObservation, _ inputImage: CVImageBuffer) -> Bool { | 220 | + func isBarCodeInScanWindow(_ scanWindow: CGRect, _ barcode: VNBarcodeObservation, _ inputImage: CVImageBuffer) -> Bool { |
| 221 | let size = CVImageBufferGetEncodedSize(inputImage) | 221 | let size = CVImageBufferGetEncodedSize(inputImage) |
| 222 | 222 | ||
| 223 | let imageWidth = size.width; | 223 | let imageWidth = size.width; |
-
Please register or login to post a comment