@sincpro/printer-expo 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +589 -415
  2. package/android/.editorconfig +20 -0
  3. package/android/README.md +103 -0
  4. package/android/build.gradle +36 -34
  5. package/android/libs/pdf/Bixolon_pdf.aar +0 -0
  6. package/android/libs/{jniLibs/x86_64/libbxl_common.so → sincpro-printer-sdk.aar} +0 -0
  7. package/android/src/main/java/sincpro/expo/printer/entrypoint/PrinterModule.kt +387 -0
  8. package/build/SincproPrinter.d.ts +191 -0
  9. package/build/SincproPrinter.d.ts.map +1 -0
  10. package/build/SincproPrinter.js +120 -0
  11. package/build/SincproPrinter.js.map +1 -0
  12. package/build/index.d.ts +11 -3
  13. package/build/index.d.ts.map +1 -1
  14. package/build/index.js +13 -3
  15. package/build/index.js.map +1 -1
  16. package/build/types/bluetooth.types.d.ts +19 -0
  17. package/build/types/bluetooth.types.d.ts.map +1 -0
  18. package/build/types/bluetooth.types.js +5 -0
  19. package/build/types/bluetooth.types.js.map +1 -0
  20. package/build/types/index.d.ts +7 -0
  21. package/build/types/index.d.ts.map +1 -0
  22. package/build/types/index.js +7 -0
  23. package/build/types/index.js.map +1 -0
  24. package/build/types/printer.types.d.ts +118 -0
  25. package/build/types/printer.types.d.ts.map +1 -0
  26. package/build/types/printer.types.js +5 -0
  27. package/build/types/printer.types.js.map +1 -0
  28. package/build/types/receipt.types.d.ts +96 -0
  29. package/build/types/receipt.types.d.ts.map +1 -0
  30. package/build/types/receipt.types.js +5 -0
  31. package/build/types/receipt.types.js.map +1 -0
  32. package/expo-module.config.json +2 -5
  33. package/package.json +6 -5
  34. package/src/SincproPrinter.ts +208 -0
  35. package/src/index.ts +15 -3
  36. package/src/types/bluetooth.types.ts +20 -0
  37. package/src/types/index.ts +7 -0
  38. package/src/types/printer.types.ts +141 -0
  39. package/src/types/receipt.types.ts +115 -0
  40. package/android/libs/BixolonLabelPrinterLibrary_V2.0.9.jar +0 -0
  41. package/android/libs/jniLibs/arm64-v8a/libbxl_common.so +0 -0
  42. package/android/libs/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
  43. package/android/libs/jniLibs/x86/libbxl_common.so +0 -0
  44. package/android/libs/libcommon_V1.4.0.jar +0 -0
  45. package/android/src/main/java/expo/sincpro/ExpoBixolonModule.kt +0 -271
  46. package/android/src/main/java/expo/sincpro/bixolon/BixolonQRPrinter.kt +0 -423
  47. package/android/src/main/java/expo/sincpro/managers/BluetoothManager.kt +0 -139
  48. package/android/src/main/java/expo/sincpro/managers/ConnectionManager.kt +0 -124
  49. package/android/src/main/java/expo/sincpro/managers/PermissionManager.kt +0 -122
  50. package/android/src/main/java/expo/sincpro/managers/PrinterManager.kt +0 -396
  51. package/android/src/main/jniLibs/arm64-v8a/libbxl_common.so +0 -0
  52. package/android/src/main/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
  53. package/android/src/main/jniLibs/x86/libbxl_common.so +0 -0
  54. package/android/src/main/jniLibs/x86_64/libbxl_common.so +0 -0
  55. package/build/BixolonPrinter.d.ts +0 -4
  56. package/build/BixolonPrinter.d.ts.map +0 -1
  57. package/build/BixolonPrinter.js +0 -12
  58. package/build/BixolonPrinter.js.map +0 -1
  59. package/build/ExpoBixolon.types.d.ts +0 -45
  60. package/build/ExpoBixolon.types.d.ts.map +0 -1
  61. package/build/ExpoBixolon.types.js +0 -2
  62. package/build/ExpoBixolon.types.js.map +0 -1
  63. package/build/ExpoBixolonModule.d.ts +0 -24
  64. package/build/ExpoBixolonModule.d.ts.map +0 -1
  65. package/build/ExpoBixolonModule.js +0 -3
  66. package/build/ExpoBixolonModule.js.map +0 -1
  67. package/build/QrCodePrinter.d.ts +0 -45
  68. package/build/QrCodePrinter.d.ts.map +0 -1
  69. package/build/QrCodePrinter.js +0 -118
  70. package/build/QrCodePrinter.js.map +0 -1
  71. package/src/BixolonPrinter.ts +0 -16
  72. package/src/ExpoBixolon.types.ts +0 -60
  73. package/src/ExpoBixolonModule.ts +0 -38
  74. package/src/QrCodePrinter.ts +0 -201
@@ -1,139 +0,0 @@
1
- package expo.sincpro.managers
2
-
3
- import android.content.Context
4
- import android.util.Log
5
- import android.bluetooth.BluetoothAdapter
6
- import android.bluetooth.BluetoothDevice
7
- import android.bluetooth.BluetoothManager
8
- import expo.sincpro.bixolon.BixolonQRPrinter
9
-
10
- class BluetoothManager(private val context: Context) {
11
- private val TAG = "BluetoothManager"
12
- private val bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
13
- private val bluetoothAdapter = bluetoothManager.adapter
14
-
15
- fun isBluetoothEnabled(): Boolean {
16
- return try {
17
- val isEnabled = bluetoothAdapter != null && bluetoothAdapter.isEnabled
18
- Log.d(TAG, "Bluetooth enabled: $isEnabled")
19
- isEnabled
20
- } catch (e: Exception) {
21
- Log.e(TAG, "Error checking Bluetooth status: ${e.message}")
22
- false
23
- }
24
- }
25
-
26
- fun discoverBluetoothDevices(): List<Map<String, Any>> {
27
- try {
28
- Log.d(TAG, "Starting Bluetooth device discovery")
29
-
30
- if (bluetoothAdapter == null) {
31
- throw Exception("Bluetooth not supported on this device")
32
- }
33
-
34
- if (!bluetoothAdapter.isEnabled) {
35
- throw Exception("Bluetooth is not enabled")
36
- }
37
-
38
- val pairedDevices = bluetoothAdapter.bondedDevices
39
- val deviceList = mutableListOf<Map<String, Any>>()
40
-
41
- for (device in pairedDevices) {
42
- val deviceInfo = mapOf(
43
- "name" to (device.name ?: "Unknown Device"),
44
- "address" to device.address,
45
- "type" to when (device.type) {
46
- BluetoothDevice.DEVICE_TYPE_CLASSIC -> "CLASSIC"
47
- BluetoothDevice.DEVICE_TYPE_LE -> "LE"
48
- BluetoothDevice.DEVICE_TYPE_DUAL -> "DUAL"
49
- else -> "UNKNOWN"
50
- },
51
- "isPrinter" to isPrinterDevice(device.name)
52
- )
53
- deviceList.add(deviceInfo)
54
- }
55
-
56
- Log.d(TAG, "Found ${deviceList.size} Bluetooth devices")
57
- return deviceList
58
-
59
- } catch (e: Exception) {
60
- Log.e(TAG, "Error discovering Bluetooth devices: ${e.message}")
61
- throw e
62
- }
63
- }
64
-
65
- fun startBluetoothDiscovery(): Boolean {
66
- try {
67
- Log.d(TAG, "Starting Bluetooth discovery")
68
-
69
- if (bluetoothAdapter == null) {
70
- throw Exception("Bluetooth not supported on this device")
71
- }
72
-
73
- if (!bluetoothAdapter.isEnabled) {
74
- throw Exception("Bluetooth is not enabled")
75
- }
76
-
77
- return if (bluetoothAdapter.startDiscovery()) {
78
- Log.d(TAG, "Bluetooth discovery started")
79
- true
80
- } else {
81
- throw Exception("Failed to start Bluetooth discovery")
82
- }
83
-
84
- } catch (e: Exception) {
85
- Log.e(TAG, "Error starting Bluetooth discovery: ${e.message}")
86
- throw e
87
- }
88
- }
89
-
90
- fun stopBluetoothDiscovery(): Boolean {
91
- try {
92
- Log.d(TAG, "Stopping Bluetooth discovery")
93
-
94
- if (bluetoothAdapter != null && bluetoothAdapter.isDiscovering) {
95
- bluetoothAdapter.cancelDiscovery()
96
- Log.d(TAG, "Bluetooth discovery stopped")
97
- }
98
-
99
- return true
100
-
101
- } catch (e: Exception) {
102
- Log.e(TAG, "Error stopping Bluetooth discovery: ${e.message}")
103
- throw e
104
- }
105
- }
106
-
107
- fun connectBluetooth(bixolonQRPrinter: BixolonQRPrinter, address: String): Boolean {
108
- return try {
109
- Log.d(TAG, "Attempting Bluetooth connection to $address using Bixolon SDK")
110
-
111
- val success = bixolonQRPrinter.connectBluetooth(address)
112
-
113
- if (success) {
114
- Log.d(TAG, "Bluetooth connection established successfully using Bixolon SDK")
115
- true
116
- } else {
117
- Log.e(TAG, "Failed to connect using Bixolon SDK")
118
- false
119
- }
120
-
121
- } catch (e: Exception) {
122
- Log.e(TAG, "Error connecting via Bluetooth: ${e.message}")
123
- false
124
- }
125
- }
126
-
127
- private fun isPrinterDevice(deviceName: String?): Boolean {
128
- if (deviceName == null) return false
129
-
130
- val printerKeywords = listOf(
131
- "printer", "print", "bixolon", "label", "thermal", "receipt",
132
- "impresora", "etiqueta", "termica", "ticket", "pos", "terminal"
133
- )
134
-
135
- return printerKeywords.any { keyword ->
136
- deviceName.lowercase().contains(keyword.lowercase())
137
- }
138
- }
139
- }
@@ -1,124 +0,0 @@
1
- package expo.sincpro.managers
2
-
3
- import android.util.Log
4
- import expo.sincpro.bixolon.BixolonQRPrinter
5
-
6
- class ConnectionManager(private val bixolonQRPrinter: BixolonQRPrinter) {
7
- private val TAG = "ConnectionManager"
8
- private var isInitialized = false
9
- private var isConnected = false
10
- private var currentAddress: String? = null
11
- private var currentPort: Int = 0
12
-
13
- fun initialize(): Boolean {
14
- return try {
15
- Log.d(TAG, "Initializing printer with Bixolon libraries")
16
-
17
- val bixolonInitialized = bixolonQRPrinter.initialize()
18
-
19
- if (bixolonInitialized) {
20
- isInitialized = true
21
- Log.d(TAG, "Printer initialized successfully with Bixolon libraries")
22
- true
23
- } else {
24
- Log.e(TAG, "Failed to initialize Bixolon printer")
25
- false
26
- }
27
- } catch (e: Exception) {
28
- Log.e(TAG, "Error initializing printer: ${e.message}")
29
- throw e
30
- }
31
- }
32
-
33
- fun connect(interfaceType: String, address: String, port: Int, bluetoothManager: BluetoothManager): Boolean {
34
- return try {
35
- Log.d(TAG, "Attempting to connect to printer via $interfaceType at $address:$port")
36
-
37
- if (!isInitialized) {
38
- throw Exception("Printer not initialized. Call initialize() first.")
39
- }
40
-
41
- currentAddress = address
42
- currentPort = port
43
-
44
- var connectionSuccess = false
45
- when (interfaceType.lowercase()) {
46
- "bluetooth" -> {
47
- Log.d(TAG, "Connecting via Bluetooth to $address")
48
- connectionSuccess = bluetoothManager.connectBluetooth(bixolonQRPrinter, address)
49
- }
50
- "wifi" -> {
51
- Log.d(TAG, "Connecting via WiFi to $address:$port")
52
- connectionSuccess = bixolonQRPrinter.connectWiFi(address, port)
53
- }
54
- "usb" -> {
55
- Log.d(TAG, "Connecting via USB")
56
- connectionSuccess = bixolonQRPrinter.connectUSB()
57
- }
58
- else -> {
59
- throw Exception("Unsupported interface type: $interfaceType")
60
- }
61
- }
62
-
63
- if (!connectionSuccess) {
64
- throw Exception("Failed to connect via $interfaceType")
65
- }
66
-
67
- isConnected = true
68
- Log.d(TAG, "Connected successfully to printer via $interfaceType")
69
-
70
- try {
71
- bixolonQRPrinter.clearAllMemory()
72
- Log.d(TAG, "Memory cleared after connection")
73
- } catch (e: Exception) {
74
- Log.w(TAG, "Warning: Could not clear memory after connection: ${e.message}")
75
- }
76
-
77
- true
78
- } catch (e: Exception) {
79
- Log.e(TAG, "Error connecting to printer: ${e.message}")
80
- throw e
81
- }
82
- }
83
-
84
- fun disconnect(): Boolean {
85
- return try {
86
- Log.d(TAG, "Disconnecting from printer")
87
-
88
- bixolonQRPrinter.disconnect()
89
-
90
- isConnected = false
91
- currentAddress = null
92
- currentPort = 0
93
-
94
- true
95
- } catch (e: Exception) {
96
- Log.e(TAG, "Error disconnecting from printer: ${e.message}")
97
- throw e
98
- }
99
- }
100
-
101
- fun executeCommand(command: String): Boolean {
102
- return try {
103
- Log.d(TAG, "Executing direct command: $command")
104
-
105
- if (!isConnected) {
106
- throw Exception("Printer not connected")
107
- }
108
-
109
- val commandBytes = command.toByteArray()
110
-
111
- Log.d(TAG, "Command '$command' sent successfully to printer")
112
- true
113
-
114
- } catch (e: Exception) {
115
- Log.e(TAG, "Error executing command: ${e.message}")
116
- throw e
117
- }
118
- }
119
-
120
- fun isInitialized(): Boolean = isInitialized
121
- fun isConnected(): Boolean = isConnected
122
- fun getCurrentAddress(): String? = currentAddress
123
- fun getCurrentPort(): Int = currentPort
124
- }
@@ -1,122 +0,0 @@
1
- package expo.sincpro.managers
2
-
3
- import android.app.Activity
4
- import android.content.Context
5
- import android.content.pm.PackageManager
6
- import android.os.Build
7
- import android.util.Log
8
- import androidx.core.app.ActivityCompat
9
- import androidx.core.content.ContextCompat
10
-
11
- class PermissionManager(private val context: Context) {
12
- private val TAG = "PermissionManager"
13
-
14
- fun requestBluetoothPermissions(currentActivity: Activity?): Boolean {
15
- try {
16
- Log.d(TAG, "Requesting Bluetooth permissions")
17
-
18
- if (currentActivity == null) {
19
- Log.w(TAG, "No current activity available for permission request")
20
- return false
21
- }
22
-
23
- val permissions = mutableListOf<String>()
24
-
25
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
26
- permissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION)
27
- }
28
-
29
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
30
- permissions.add(android.Manifest.permission.ACCESS_COARSE_LOCATION)
31
- }
32
-
33
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
34
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
35
- permissions.add(android.Manifest.permission.BLUETOOTH_SCAN)
36
- }
37
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
38
- permissions.add(android.Manifest.permission.BLUETOOTH_CONNECT)
39
- }
40
- }
41
-
42
- if (permissions.isEmpty()) {
43
- Log.d(TAG, "All permissions already granted")
44
- return true
45
- }
46
-
47
- Log.d(TAG, "Requesting permissions: ${permissions.joinToString()}")
48
-
49
- ActivityCompat.requestPermissions(
50
- currentActivity,
51
- permissions.toTypedArray(),
52
- 1001
53
- )
54
-
55
- return true
56
-
57
- } catch (e: Exception) {
58
- Log.e(TAG, "Error requesting Bluetooth permissions: ${e.message}")
59
- return false
60
- }
61
- }
62
-
63
- fun checkBluetoothPermissions(): Map<String, Boolean> {
64
- try {
65
- Log.d(TAG, "Checking Bluetooth permissions")
66
-
67
- val results = mutableMapOf<String, Boolean>()
68
-
69
- results["ACCESS_FINE_LOCATION"] = ContextCompat.checkSelfPermission(
70
- context,
71
- android.Manifest.permission.ACCESS_FINE_LOCATION
72
- ) == PackageManager.PERMISSION_GRANTED
73
-
74
- results["ACCESS_COARSE_LOCATION"] = ContextCompat.checkSelfPermission(
75
- context,
76
- android.Manifest.permission.ACCESS_COARSE_LOCATION
77
- ) == PackageManager.PERMISSION_GRANTED
78
-
79
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
80
- results["BLUETOOTH_SCAN"] = ContextCompat.checkSelfPermission(
81
- context,
82
- android.Manifest.permission.BLUETOOTH_SCAN
83
- ) == PackageManager.PERMISSION_GRANTED
84
-
85
- results["BLUETOOTH_CONNECT"] = ContextCompat.checkSelfPermission(
86
- context,
87
- android.Manifest.permission.BLUETOOTH_CONNECT
88
- ) == PackageManager.PERMISSION_GRANTED
89
- }
90
-
91
- return results
92
-
93
- } catch (e: Exception) {
94
- Log.e(TAG, "Error checking Bluetooth permissions: ${e.message}")
95
- throw e
96
- }
97
- }
98
-
99
- fun hasRequiredPermissions(): Boolean {
100
- val hasLocationPermission = ContextCompat.checkSelfPermission(
101
- context,
102
- android.Manifest.permission.ACCESS_FINE_LOCATION
103
- ) == PackageManager.PERMISSION_GRANTED
104
-
105
- var hasBluetoothPermissions = true
106
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
107
- val hasScanPermission = ContextCompat.checkSelfPermission(
108
- context,
109
- android.Manifest.permission.BLUETOOTH_SCAN
110
- ) == PackageManager.PERMISSION_GRANTED
111
-
112
- val hasConnectPermission = ContextCompat.checkSelfPermission(
113
- context,
114
- android.Manifest.permission.BLUETOOTH_CONNECT
115
- ) == PackageManager.PERMISSION_GRANTED
116
-
117
- hasBluetoothPermissions = hasScanPermission && hasConnectPermission
118
- }
119
-
120
- return hasLocationPermission && hasBluetoothPermissions
121
- }
122
- }