ns-bxl-label 1.0.3 → 1.0.5

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.
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export interface PrinterCallbacks {
2
+ onConnectionStateChanged?: (status: string) => void;
3
+ onPrintStarted?: () => void;
4
+ onPrintSuccess?: () => void;
5
+ onPrintError?: (error: string) => void;
6
+ onConnectionFailed?: (error: string) => void;
7
+ onConnectionLost?: () => void;
8
+ showPrintingDialog?: () => void;
9
+ hidePrintingDialog?: () => void;
10
+ }
11
+
12
+ export function startBluetoothPrintFlow(
13
+ printerAddress: string,
14
+ zplCommand: string,
15
+ callbacks?: PrinterCallbacks
16
+ ): void;
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ const { startBluetoothPrintFlow } = require("./src/index");
2
+
3
+ module.exports = {
4
+ startBluetoothPrintFlow
5
+ };
package/package.json CHANGED
@@ -1,35 +1,37 @@
1
1
  {
2
2
  "name": "ns-bxl-label",
3
- "version": "1.0.3",
4
- "main": "src/index.js",
5
- "types": "src/index.d.ts",
6
-
3
+ "version": "1.0.5",
4
+ "main": "index.js",
5
+ "types": "index.d.ts",
7
6
  "nativescript": {
8
7
  "platforms": {
9
8
  "android": "8.0.0"
9
+ },
10
+ "plugin": {
11
+ "name": "ns-bxl-label"
10
12
  }
11
13
  },
12
-
13
14
  "peerDependencies": {
14
15
  "@nativescript/core": "^8.0.0"
15
16
  },
16
-
17
17
  "dependencies": {
18
18
  "nativescript-permissions": "^1.3.0"
19
19
  },
20
-
21
20
  "files": [
21
+ "index.js",
22
+ "index.d.ts",
22
23
  "src/",
23
- "src/platform-android/",
24
+ "platforms/",
24
25
  "plugin.xml",
25
26
  "package.json",
26
27
  "README.md"
27
28
  ],
28
-
29
29
  "keywords": [
30
30
  "bxl"
31
31
  ],
32
-
33
32
  "author": "n",
34
- "license": "MIT"
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "typescript": "^5.9.3"
36
+ }
35
37
  }
@@ -0,0 +1,11 @@
1
+ android {
2
+ defaultConfig {
3
+ minSdkVersion 21
4
+ targetSdkVersion 35
5
+ }
6
+ }
7
+
8
+ dependencies {
9
+ implementation files('libs/BixolonLabelPrinterLibrary_V2.0.9.jar')
10
+ implementation files('libs/libcommon_V1.4.0.jar')
11
+ }
package/plugin.xml CHANGED
@@ -1,38 +1,34 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <plugin>
3
- <platforms>
4
- <android>
5
-
6
- <!-- Archivos Java del plugin -->
7
- <files>
8
- <file>src/platform-android/com/rivercon/appprintbixolon/PrinterControl/BixolonPrinterConnector.java</file>
9
- <file>src/platform-android/com/rivercon/appprintbixolon/PrinterControl/BixolonPrinterManager.java</file>
10
- <file>src/platform-android/com/rivercon/appprintbixolon/PrinterControl/LabelPrinterHelper.java</file>
11
- <file>src/platform-android/com/rivercon/appprintbixolon/PrinterControl/PrinterDialogManager.java</file>
12
- <file>src/platform-android/com/rivercon/appprintbixolon/PrinterControl/PrinterStateListener.java</file>
13
-
14
- <!-- SDK Bixolon -->
15
- <file>src/platform-android/libs/bixolon-labelprinter.jar</file>
16
- </files>
17
-
18
- <!-- Permisos necesarios para Android 12+ -->
19
- <manifest>
20
- <uses-permission android:name="android.permission.BLUETOOTH" />
21
- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
22
- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
23
- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
24
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
25
- </manifest>
26
-
27
- </android>
28
- </platforms>
29
-
30
- <!-- Módulo JS/TS del plugin -->
31
- <js-module name="index" path="src/index.js">
32
- <android>
33
- <!-- Paquete donde vive tu @JavaProxy -->
34
- <java-package>com.rivercon.appprintbixolon.PrinterControl</java-package>
35
- </android>
36
- </js-module>
2
+ <plugin id="ns-bxl-label" version="1.0.5" xmlns="http://www.nativescript.org/ns/plugins">
3
+
4
+ <platform name="android">
5
+
6
+ <!-- Gradle -->
7
+ <framework src="platforms/android/include.gradle" />
8
+
9
+ <!-- Archivos Java -->
10
+ <source-file src="platforms/android/src/main/java/com/rivercon/appprintbixolon/PrinterControl/BixolonPrinterConnector.java" />
11
+ <source-file src="platforms/android/src/main/java/com/rivercon/appprintbixolon/PrinterControl/BixolonPrinterManager.java" />
12
+ <source-file src="platforms/android/src/main/java/com/rivercon/appprintbixolon/PrinterControl/LabelPrinterHelper.java" />
13
+ <source-file src="platforms/android/src/main/java/com/rivercon/appprintbixolon/PrinterControl/PrinterDialog.java" />
14
+ <source-file src="platforms/android/src/main/java/com/rivercon/appprintbixolon/PrinterControl/PrinterStateListener.java" />
15
+
16
+ <!-- JARs -->
17
+ <source-file src="platforms/android/libs/BixolonLabelPrinterLibrary_V2.0.9.jar" />
18
+ <source-file src="platforms/android/libs/libcommon_V1.4.0.jar" />
19
+
20
+ <!-- Permisos -->
21
+ <config-file target="AndroidManifest.xml" parent="/manifest">
22
+ <uses-permission android:name="android.permission.BLUETOOTH" />
23
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
24
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
25
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
26
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
27
+ </config-file>
28
+
29
+ </platform>
30
+
31
+ <!-- API JS -->
32
+ <js-module name="index" path="index.js" />
37
33
 
38
34
  </plugin>
package/src/index.js ADDED
@@ -0,0 +1,116 @@
1
+ const application = require("@nativescript/core/application");
2
+ const Dialogs = require("@nativescript/core").Dialogs;
3
+ const permissions = require("nativescript-permissions");
4
+
5
+ function PrinterStateListenerImpl(callbacks) {
6
+ this.callbacks = callbacks || {};
7
+ return global.__native(this);
8
+ }
9
+
10
+ PrinterStateListenerImpl.prototype = Object.create(java.lang.Object.prototype);
11
+ PrinterStateListenerImpl.prototype.constructor = PrinterStateListenerImpl;
12
+
13
+ PrinterStateListenerImpl.prototype.onConnectionStateChanged = function (status) {
14
+ if (this.callbacks.onConnectionStateChanged) {
15
+ this.callbacks.onConnectionStateChanged(status);
16
+ }
17
+ };
18
+
19
+ PrinterStateListenerImpl.prototype.showPrintingDialog = function () {
20
+ if (this.callbacks.showPrintingDialog) {
21
+ this.callbacks.showPrintingDialog();
22
+ }
23
+ };
24
+
25
+ PrinterStateListenerImpl.prototype.hidePrintingDialog = function () {
26
+ if (this.callbacks.hidePrintingDialog) {
27
+ this.callbacks.hidePrintingDialog();
28
+ }
29
+ };
30
+
31
+ PrinterStateListenerImpl.prototype.onPrintError = function (errorMessage) {
32
+ if (this.callbacks.onPrintError) {
33
+ this.callbacks.onPrintError(errorMessage);
34
+ }
35
+ };
36
+
37
+ PrinterStateListenerImpl.prototype.onConnectionFailed = function (errorMessage) {
38
+ if (this.callbacks.onConnectionFailed) {
39
+ this.callbacks.onConnectionFailed(errorMessage);
40
+ }
41
+ };
42
+
43
+ PrinterStateListenerImpl.prototype.onConnectionLost = function () {
44
+ if (this.callbacks.onConnectionLost) {
45
+ this.callbacks.onConnectionLost();
46
+ }
47
+ };
48
+
49
+ PrinterStateListenerImpl.prototype.onPrintSuccess = function () {
50
+ if (this.callbacks.onPrintSuccess) {
51
+ this.callbacks.onPrintSuccess();
52
+ }
53
+ };
54
+
55
+ function startBluetoothPrintFlow(printerAddress, zplCommand, callbacks) {
56
+ callbacks = callbacks || {};
57
+ const context = application.android.context;
58
+
59
+ if (!printerAddress || printerAddress.trim() === "") {
60
+ Dialogs.alert("No se ha especificado la dirección de la impresora.");
61
+ return;
62
+ }
63
+
64
+ if (!zplCommand || zplCommand.trim() === "") {
65
+ Dialogs.alert("No hay ZPL para imprimir.");
66
+ return;
67
+ }
68
+
69
+ const requiredPermissions = [
70
+ android.Manifest.permission.BLUETOOTH_CONNECT,
71
+ android.Manifest.permission.BLUETOOTH_SCAN,
72
+ android.Manifest.permission.ACCESS_FINE_LOCATION
73
+ ];
74
+
75
+ permissions.requestPermissions(requiredPermissions, "Se requieren permisos para imprimir")
76
+ .then(() => {
77
+ try {
78
+ if (callbacks.onPrintStarted) {
79
+ callbacks.onPrintStarted();
80
+ }
81
+
82
+ const listener = new PrinterStateListenerImpl({
83
+ onConnectionStateChanged: callbacks.onConnectionStateChanged,
84
+ showPrintingDialog: callbacks.showPrintingDialog,
85
+ hidePrintingDialog: callbacks.hidePrintingDialog,
86
+ onPrintError: callbacks.onPrintError,
87
+ onConnectionFailed: callbacks.onConnectionFailed,
88
+ onConnectionLost: callbacks.onConnectionLost,
89
+ onPrintSuccess: callbacks.onPrintSuccess
90
+ });
91
+
92
+ const Manager = com.rivercon.appprintbixolon.PrinterControl.BixolonPrinterManager;
93
+ const manager = new Manager(context, listener);
94
+
95
+ manager.startFullSequence(printerAddress, zplCommand);
96
+
97
+ } catch (e) {
98
+ if (callbacks.onPrintError) {
99
+ callbacks.onPrintError("Error general en flujo de impresión: " + e.message);
100
+ } else {
101
+ Dialogs.alert("Error general en flujo de impresión: " + e.message);
102
+ }
103
+ }
104
+ })
105
+ .catch((err) => {
106
+ if (callbacks.onPrintError) {
107
+ callbacks.onPrintError("Permisos denegados: " + err);
108
+ } else {
109
+ Dialogs.alert("Permisos denegados: " + err);
110
+ }
111
+ });
112
+ }
113
+
114
+ module.exports = {
115
+ startBluetoothPrintFlow
116
+ };