Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The changes documented here do not include those from the original repository.

## [2.0.0]

### 01-09-2025

- Feature: Android - provide `hint` and return `format`.

**BREAKING CHANGES**: The `scanBarcode` now returns an object instead of a string.

## [1.2.1]

### 20-08-2025
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.outsystems.plugins.barcode",
"version": "1.2.1",
"version": "2.0.0",
"description": "Cordova Bridge for the OutSystems Officially Supported Barcode Plugin.",
"keywords": [
"ecosystem:cordova",
Expand Down
9 changes: 5 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin id="com.outsystems.plugins.barcode" version="1.2.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="com.outsystems.plugins.barcode" version="2.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>OSBarcode</name>
<description>Cordova Bridge for the OutSystems Officially Supported Barcode Plugin.</description>
<author>OutSystems Inc</author>
Expand All @@ -26,6 +26,7 @@
<config-file parent="/*" target="AndroidManifest.xml"/>
<source-file src="src/android/com/outsystems/plugins/barcode/OSBarcode.kt" target-dir="app/src/main/kotlin/com/outsystems/plugins/barcode"/>
<framework src="src/android/com/outsystems/plugins/barcode/build.gradle" custom="true" type="gradleReference" />

</platform>
<platform name="ios">
<config-file parent="/*" target="config.xml">
Expand All @@ -42,16 +43,16 @@

<source-file src="src/ios/OSBarcode.swift" />
<source-file src="src/ios/OSBarcodeError.swift" />
<source-file src="src/ios/OSBarcodeScanArgumentsModel.swift" />


<source-file src="src/ios/OSBARCArgumentMappable.swift" target-dir="extensions" />
<source-file src="src/ios/OSBARCScanParameters+Decodable.swift" target-dir="extensions" />

<podspec>
<config>
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="OSBarcodeLib" spec="1.1.3" />
<pod name="OSBarcodeLib" spec="2.0.1" />
</pods>
</podspec>
</platform>
Expand Down
36 changes: 31 additions & 5 deletions src/android/com/outsystems/plugins/barcode/OSBarcode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@ package com.outsystems.plugins.barcode

import android.content.Intent
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.outsystems.plugins.barcode.controller.OSBARCController
import com.outsystems.plugins.barcode.model.OSBARCError
import com.outsystems.plugins.barcode.model.OSBARCScanParameters
import com.outsystems.plugins.barcode.model.OSBARCScanResult
import com.outsystems.plugins.barcode.model.OSBARCScannerHint
import com.outsystems.plugins.oscordova.CordovaImplementation
import kotlinx.coroutines.runBlocking
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaInterface
import org.apache.cordova.CordovaWebView
import org.json.JSONArray
import org.json.JSONObject
import java.lang.reflect.Type

class OSBarcode : CordovaImplementation() {

companion object {
private const val ERROR_FORMAT_PREFIX = "OS-PLUG-BARC-"
}

override var callbackContext: CallbackContext? = null
private lateinit var barcodeController: OSBARCController
val gson by lazy { Gson() }
val gson: Gson by lazy {
GsonBuilder()
.registerTypeAdapter(OSBARCScannerHint::class.java, OSBARCScannerHintAdapter())
.create()
}

override fun execute(
action: String,
Expand All @@ -45,8 +55,12 @@ class OSBarcode : CordovaImplementation() {
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
barcodeController.handleActivityResult(requestCode, resultCode, intent,
{ result ->
sendPluginResult(result, null)
{ result: OSBARCScanResult ->
val jsonObject = JSONObject().apply {
put("ScanResult", result.text)
put("format", result.format.ordinal)
}
sendPluginResult(jsonObject, null)
},
{ error ->
sendPluginResult(null, Pair(formatErrorCode(error.code), error.description))
Expand Down Expand Up @@ -98,4 +112,16 @@ class OSBarcode : CordovaImplementation() {
return ERROR_FORMAT_PREFIX + code.toString().padStart(4, '0')
}

private class OSBARCScannerHintAdapter : JsonDeserializer<OSBARCScannerHint> {
override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?
): OSBARCScannerHint {
return json?.asInt?.let {
OSBARCScannerHint.entries.getOrNull(it)
} ?: OSBARCScannerHint.UNKNOWN
}
}

}
2 changes: 1 addition & 1 deletion src/android/com/outsystems/plugins/barcode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories{
dependencies {
implementation("com.github.outsystems:oscore-android:1.2.0@aar")
implementation("com.github.outsystems:oscordova-android:2.0.1@aar")
implementation("io.ionic.libs:ionbarcode-android:1.2.1@aar")
implementation("io.ionic.libs:ionbarcode-android:2.0.0@aar")

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation "androidx.activity:activity-ktx:1.9.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import OSBarcodeLib

struct OSBarcodeScanArgumentsModel: Decodable {
let scanInstructions: String
let scanButtonText: String?
let cameraDirection: OSBARCCameraModel
let scanOrientation: OSBARCOrientationModel
extension OSBARCScanParameters: Decodable {

enum CodingKeys: CodingKey {
case scanButton
case scanInstructions
case scanText
case cameraDirection
case scanOrientation
case hint
}

init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

let scanInstructions = try container.decode(String.self, forKey: .scanInstructions)
Expand All @@ -31,13 +28,15 @@ struct OSBarcodeScanArgumentsModel: Decodable {
let scanOrientationInt = try container.decode(Int.self, forKey: .scanOrientation)
let scanOrientation = OSBARCOrientationModel(value: scanOrientationInt)

self.init(scanInstructions, scanButtonText, cameraDirection, scanOrientation)
}

private init(_ scanInstructions: String, _ scanButtonText: String?, _ cameraDirection: OSBARCCameraModel, _ scanOrientation: OSBARCOrientationModel) {
self.scanInstructions = scanInstructions
self.scanButtonText = scanButtonText
self.cameraDirection = cameraDirection
self.scanOrientation = scanOrientation
let hintInt = try container.decode(Int.self, forKey: .hint)
let hint = OSBARCScannerHint(rawValue: hintInt)

self.init(
scanInstructions: scanInstructions,
scanButtonText: scanButtonText,
cameraDirection: cameraDirection,
scanOrientation: scanOrientation,
hint: hint
)
}
}
11 changes: 6 additions & 5 deletions src/ios/OSBarcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class OSBarcode: CDVPlugin {

guard let argumentsDictionary = command.argument(at: 0) as? [String: Any],
let argumentsData = try? JSONSerialization.data(withJSONObject: argumentsDictionary),
let argumentsModel = try? JSONDecoder().decode(OSBarcodeScanArgumentsModel.self, from: argumentsData)
let parameters = try? JSONDecoder().decode(OSBARCScanParameters.self, from: argumentsData)
else { return self.send(error: .scanInputArgumentsIssue, for: command.callbackId) }

Task {
do {
guard let scannedBarcode = try await self.plugin?.scanBarcode(with: argumentsModel.scanInstructions, argumentsModel.scanButtonText, argumentsModel.cameraDirection, and: argumentsModel.scanOrientation) else {
guard let scanResult = try await self.plugin?.scanBarcode(with: parameters) else {
return self.send(error: .scanningError, for: command.callbackId)
}
self.send(successfulResult: scannedBarcode, for: command.callbackId)
self.send(successfulResult: scanResult, for: command.callbackId)
} catch OSBARCManagerError.cameraAccessDenied {
self.send(error: .cameraAccessDenied, for: command.callbackId)
} catch OSBARCManagerError.scanningCancelled {
Expand All @@ -37,8 +37,9 @@ class OSBarcode: CDVPlugin {
}

private extension OSBarcode {
func send(successfulResult: String, for callbackId: String) {
let pluginResult = CDVPluginResult(status: .ok, messageAs: successfulResult)
func send(successfulResult: OSBARCScanResult, for callbackId: String) {
let resultDict: [String : Any] = ["ScanResult": successfulResult.text, "format": successfulResult.format.rawValue]
let pluginResult = CDVPluginResult(status: .ok, messageAs: resultDict)
self.commandDelegate.send(pluginResult, callbackId: callbackId)
}

Expand Down