ns-bxl-label 1.0.4 → 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/package.json +8 -8
- package/plugin.xml +1 -1
- package/src/index.js +116 -0
- /package/{platforms/android/src → src}/index.ts +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ns-bxl-label",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
|
-
|
|
7
6
|
"nativescript": {
|
|
8
7
|
"platforms": {
|
|
9
8
|
"android": "8.0.0"
|
|
@@ -12,15 +11,12 @@
|
|
|
12
11
|
"name": "ns-bxl-label"
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
|
-
|
|
16
14
|
"peerDependencies": {
|
|
17
15
|
"@nativescript/core": "^8.0.0"
|
|
18
16
|
},
|
|
19
|
-
|
|
20
17
|
"dependencies": {
|
|
21
18
|
"nativescript-permissions": "^1.3.0"
|
|
22
19
|
},
|
|
23
|
-
|
|
24
20
|
"files": [
|
|
25
21
|
"index.js",
|
|
26
22
|
"index.d.ts",
|
|
@@ -30,8 +26,12 @@
|
|
|
30
26
|
"package.json",
|
|
31
27
|
"README.md"
|
|
32
28
|
],
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
"keywords": [
|
|
30
|
+
"bxl"
|
|
31
|
+
],
|
|
35
32
|
"author": "n",
|
|
36
|
-
"license": "MIT"
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
37
37
|
}
|
package/plugin.xml
CHANGED
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
|
+
};
|
|
File without changes
|