seven365-zyprinter 1.0.5 → 1.0.7

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 CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "seven365-zyprinter",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Capacitor plugin for Zywell/Zyprint thermal printer integration with Bluetooth and WiFi support",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
8
8
  "unpkg": "dist/plugin.js",
9
9
  "files": [
10
- "android/src/main/",
11
- "android/build.gradle",
12
10
  "dist/",
13
11
  "ios/Sources",
14
12
  "ios/Tests",
@@ -37,9 +35,8 @@
37
35
  "wifi"
38
36
  ],
39
37
  "scripts": {
40
- "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
38
+ "verify": "npm run verify:ios && npm run verify:web",
41
39
  "verify:ios": "xcodebuild -scheme Seven365Zyprinter -destination generic/platform=iOS",
42
- "verify:android": "cd android && ./gradlew clean build test && cd ..",
43
40
  "verify:web": "npm run build",
44
41
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
45
42
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
@@ -53,7 +50,6 @@
53
50
  "prepublishOnly": "npm run build"
54
51
  },
55
52
  "devDependencies": {
56
- "@capacitor/android": "^7.0.0",
57
53
  "@capacitor/cli": "^7.4.4",
58
54
  "@capacitor/core": "^7.0.0",
59
55
  "@capacitor/docgen": "^0.3.0",
@@ -80,9 +76,6 @@
80
76
  "capacitor": {
81
77
  "ios": {
82
78
  "src": "ios"
83
- },
84
- "android": {
85
- "src": "android"
86
79
  }
87
80
  },
88
81
  "dependencies": {
@@ -1,58 +0,0 @@
1
- ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
- }
7
-
8
- buildscript {
9
- repositories {
10
- google()
11
- mavenCentral()
12
- }
13
- dependencies {
14
- classpath 'com.android.tools.build:gradle:8.7.2'
15
- }
16
- }
17
-
18
- apply plugin: 'com.android.library'
19
-
20
- android {
21
- namespace "com.mycompany.plugins.example"
22
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
- defaultConfig {
24
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
- versionCode 1
27
- versionName "1.0"
28
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
- }
30
- buildTypes {
31
- release {
32
- minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
- }
35
- }
36
- lintOptions {
37
- abortOnError false
38
- }
39
- compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_21
41
- targetCompatibility JavaVersion.VERSION_21
42
- }
43
- }
44
-
45
- repositories {
46
- google()
47
- mavenCentral()
48
- }
49
-
50
-
51
- dependencies {
52
- implementation fileTree(dir: 'libs', include: ['*.jar'])
53
- implementation project(':capacitor-android')
54
- implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
- testImplementation "junit:junit:$junitVersion"
56
- androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
- androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
- }
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,461 +0,0 @@
1
- package com.mycompany.plugins.example;
2
-
3
- import android.bluetooth.BluetoothAdapter;
4
- import android.bluetooth.BluetoothDevice;
5
- import android.bluetooth.BluetoothSocket;
6
- import android.content.Context;
7
- import android.util.Log;
8
- import android.os.Handler;
9
- import android.os.Looper;
10
-
11
- import com.getcapacitor.JSArray;
12
- import com.getcapacitor.JSObject;
13
-
14
- import java.io.IOException;
15
- import java.io.OutputStream;
16
- import java.net.Socket;
17
- import java.util.HashMap;
18
- import java.util.Map;
19
- import java.util.Set;
20
- import java.util.UUID;
21
-
22
- public class Zyprint {
23
-
24
- private static final String TAG = "Zyprint";
25
- private Map<String, PrinterConnection> connectedPrinters = new HashMap<>();
26
- private Handler mainHandler = new Handler(Looper.getMainLooper());
27
-
28
- // Callback interfaces
29
- public interface PrinterDiscoveryCallback {
30
- void onPrintersFound(JSArray printers);
31
- void onError(String error);
32
- }
33
-
34
- public interface ConnectionCallback {
35
- void onConnected();
36
- void onError(String error);
37
- }
38
-
39
- public interface DisconnectionCallback {
40
- void onDisconnected();
41
- void onError(String error);
42
- }
43
-
44
- public interface PrintCallback {
45
- void onSuccess();
46
- void onError(String error);
47
- }
48
-
49
- public interface StatusCallback {
50
- void onStatus(String status, String paperStatus, boolean connected);
51
- void onError(String error);
52
- }
53
-
54
- public String echo(String value) {
55
- Log.i(TAG, "Echo: " + value);
56
- return value;
57
- }
58
-
59
- public void discoverPrinters(PrinterDiscoveryCallback callback) {
60
- new Thread(() -> {
61
- try {
62
- JSArray printers = new JSArray();
63
-
64
- // Discover Bluetooth printers
65
- BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
66
- if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
67
- Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
68
-
69
- for (BluetoothDevice device : pairedDevices) {
70
- // Filter for printer devices (you may need to adjust this based on Zywell printer naming)
71
- if (device.getName() != null &&
72
- (device.getName().toLowerCase().contains("zywell") ||
73
- device.getName().toLowerCase().contains("zyprint") ||
74
- device.getName().toLowerCase().contains("printer"))) {
75
-
76
- JSObject printer = new JSObject();
77
- printer.put("identifier", device.getAddress());
78
- printer.put("model", device.getName());
79
- printer.put("status", device.getBondState() == BluetoothDevice.BOND_BONDED ? "ready" : "offline");
80
- printers.put(printer);
81
- }
82
- }
83
- }
84
-
85
- mainHandler.post(() -> callback.onPrintersFound(printers));
86
-
87
- } catch (Exception e) {
88
- Log.e(TAG, "Error discovering printers", e);
89
- mainHandler.post(() -> callback.onError("Discovery failed: " + e.getMessage()));
90
- }
91
- }).start();
92
- }
93
-
94
- public void connectToPrinter(String identifier, ConnectionCallback callback) {
95
- new Thread(() -> {
96
- try {
97
- PrinterConnection connection = new PrinterConnection();
98
-
99
- // Try to connect via Bluetooth
100
- BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
101
- if (bluetoothAdapter != null) {
102
- BluetoothDevice device = bluetoothAdapter.getRemoteDevice(identifier);
103
-
104
- if (connection.connectBluetooth(device)) {
105
- connectedPrinters.put(identifier, connection);
106
- mainHandler.post(callback::onConnected);
107
- return;
108
- }
109
- }
110
-
111
- // If Bluetooth fails, try WiFi (if identifier is an IP address)
112
- if (identifier.matches("\\d+\\.\\d+\\.\\d+\\.\\d+")) {
113
- if (connection.connectWiFi(identifier, 9100)) {
114
- connectedPrinters.put(identifier, connection);
115
- mainHandler.post(callback::onConnected);
116
- return;
117
- }
118
- }
119
-
120
- mainHandler.post(() -> callback.onError("Connection failed"));
121
-
122
- } catch (Exception e) {
123
- Log.e(TAG, "Error connecting to printer", e);
124
- mainHandler.post(() -> callback.onError("Connection failed: " + e.getMessage()));
125
- }
126
- }).start();
127
- }
128
-
129
- public void disconnectFromPrinter(String identifier, DisconnectionCallback callback) {
130
- PrinterConnection connection = connectedPrinters.get(identifier);
131
- if (connection != null) {
132
- connection.disconnect();
133
- connectedPrinters.remove(identifier);
134
- callback.onDisconnected();
135
- } else {
136
- callback.onError("Printer not connected");
137
- }
138
- }
139
-
140
- public void printText(String text, String identifier, PrintCallback callback) {
141
- PrinterConnection connection = connectedPrinters.get(identifier);
142
- if (connection == null) {
143
- callback.onError("Printer not connected");
144
- return;
145
- }
146
-
147
- new Thread(() -> {
148
- try {
149
- byte[] data = formatTextForPrinter(text);
150
- if (connection.sendData(data)) {
151
- mainHandler.post(callback::onSuccess);
152
- } else {
153
- mainHandler.post(() -> callback.onError("Print failed"));
154
- }
155
- } catch (Exception e) {
156
- Log.e(TAG, "Error printing text", e);
157
- mainHandler.post(() -> callback.onError("Print failed: " + e.getMessage()));
158
- }
159
- }).start();
160
- }
161
-
162
- public void printReceipt(JSObject template, String identifier, PrintCallback callback) {
163
- PrinterConnection connection = connectedPrinters.get(identifier);
164
- if (connection == null) {
165
- callback.onError("Printer not connected");
166
- return;
167
- }
168
-
169
- new Thread(() -> {
170
- try {
171
- byte[] data = formatReceiptForPrinter(template);
172
- if (connection.sendData(data)) {
173
- mainHandler.post(callback::onSuccess);
174
- } else {
175
- mainHandler.post(() -> callback.onError("Print failed"));
176
- }
177
- } catch (Exception e) {
178
- Log.e(TAG, "Error printing receipt", e);
179
- mainHandler.post(() -> callback.onError("Print failed: " + e.getMessage()));
180
- }
181
- }).start();
182
- }
183
-
184
- public void getPrinterStatus(String identifier, StatusCallback callback) {
185
- PrinterConnection connection = connectedPrinters.get(identifier);
186
- if (connection == null) {
187
- callback.onStatus("offline", "unknown", false);
188
- return;
189
- }
190
-
191
- new Thread(() -> {
192
- try {
193
- // Send status command (this would be specific to Zywell protocol)
194
- byte[] statusCommand = {0x10, 0x04, 0x01}; // Example status command
195
-
196
- if (connection.sendData(statusCommand)) {
197
- // In a real implementation, you'd read the response and parse it
198
- mainHandler.post(() -> callback.onStatus("ready", "ok", true));
199
- } else {
200
- mainHandler.post(() -> callback.onStatus("error", "unknown", true));
201
- }
202
- } catch (Exception e) {
203
- Log.e(TAG, "Error getting printer status", e);
204
- mainHandler.post(() -> callback.onError("Status check failed: " + e.getMessage()));
205
- }
206
- }).start();
207
- }
208
-
209
- private byte[] formatTextForPrinter(String text) {
210
- try {
211
- // ESC/POS commands for text printing
212
- byte[] initPrinter = {0x1B, 0x40}; // ESC @
213
- byte[] textBytes = text.getBytes("UTF-8");
214
- byte[] lineFeed = {0x0A, 0x0A, 0x0A}; // Line feeds
215
- byte[] cutPaper = {0x1D, 0x56, 0x41, 0x10}; // Cut command
216
-
217
- byte[] result = new byte[initPrinter.length + textBytes.length + lineFeed.length + cutPaper.length];
218
- int offset = 0;
219
-
220
- System.arraycopy(initPrinter, 0, result, offset, initPrinter.length);
221
- offset += initPrinter.length;
222
-
223
- System.arraycopy(textBytes, 0, result, offset, textBytes.length);
224
- offset += textBytes.length;
225
-
226
- System.arraycopy(lineFeed, 0, result, offset, lineFeed.length);
227
- offset += lineFeed.length;
228
-
229
- System.arraycopy(cutPaper, 0, result, offset, cutPaper.length);
230
-
231
- return result;
232
- } catch (Exception e) {
233
- Log.e(TAG, "Error formatting text", e);
234
- return new byte[0];
235
- }
236
- }
237
-
238
- private byte[] formatReceiptForPrinter(JSObject template) {
239
- try {
240
- StringBuilder receiptText = new StringBuilder();
241
-
242
- // Initialize printer
243
- receiptText.append("\u001B@"); // ESC @
244
-
245
- // Center align
246
- receiptText.append("\u001B\u0061\u0001"); // ESC a 1
247
-
248
- // Header
249
- if (template.has("header")) {
250
- // Get header size from formatting
251
- byte sizeCode = 0x00; // Default: normal
252
- if (template.has("formatting")) {
253
- JSObject formatting = template.getJSObject("formatting");
254
- if (formatting != null && formatting.has("headerSize")) {
255
- sizeCode = mapHeaderSizeToCode(formatting.get("headerSize"));
256
- }
257
- }
258
-
259
- // Set font size (GS ! n)
260
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) sizeCode);
261
-
262
- receiptText.append(template.getString("header")).append("\n\n");
263
-
264
- // Reset to normal size
265
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) 0x00);
266
- }
267
-
268
- // Left align for items
269
- receiptText.append("\u001B\u0061\u0000"); // ESC a 0
270
-
271
- // Items
272
- if (template.has("items")) {
273
- // Get item formatting
274
- byte itemSizeCode = 0x00;
275
- boolean itemBold = false;
276
- if (template.has("formatting")) {
277
- JSObject formatting = template.getJSObject("formatting");
278
- if (formatting != null) {
279
- if (formatting.has("itemSize")) {
280
- itemSizeCode = mapHeaderSizeToCode(formatting.get("itemSize"));
281
- }
282
- itemBold = formatting.optBoolean("itemBold", false);
283
- }
284
- }
285
-
286
- // Apply item formatting
287
- if (itemBold) {
288
- receiptText.append((char) 0x1B).append((char) 0x45).append((char) 0x01); // Bold on
289
- }
290
- if (itemSizeCode != 0x00) {
291
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) itemSizeCode); // Set size
292
- }
293
-
294
- JSArray items = template.getJSArray("items");
295
- for (int i = 0; i < items.length(); i++) {
296
- JSObject item = items.getJSObject(i);
297
- String name = item.optString("name", "");
298
- String price = item.optString("price", "");
299
- receiptText.append(name).append("\t").append(price).append("\n");
300
- }
301
-
302
- // Reset item formatting
303
- if (itemSizeCode != 0x00) {
304
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) 0x00); // Normal size
305
- }
306
- if (itemBold) {
307
- receiptText.append((char) 0x1B).append((char) 0x45).append((char) 0x00); // Bold off
308
- }
309
- }
310
-
311
- // Total
312
- if (template.has("total")) {
313
- // Get total formatting
314
- byte totalSizeCode = 0x00;
315
- boolean totalBold = false;
316
- if (template.has("formatting")) {
317
- JSObject formatting = template.getJSObject("formatting");
318
- if (formatting != null) {
319
- if (formatting.has("totalSize")) {
320
- totalSizeCode = mapHeaderSizeToCode(formatting.get("totalSize"));
321
- }
322
- totalBold = formatting.optBoolean("totalBold", false);
323
- }
324
- }
325
-
326
- // Apply total formatting
327
- if (totalBold) {
328
- receiptText.append((char) 0x1B).append((char) 0x45).append((char) 0x01); // Bold on
329
- }
330
- if (totalSizeCode != 0x00) {
331
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) totalSizeCode); // Set size
332
- }
333
-
334
- receiptText.append("\nTotal: ").append(template.getString("total")).append("\n");
335
-
336
- // Reset total formatting
337
- if (totalSizeCode != 0x00) {
338
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) 0x00); // Normal size
339
- }
340
- if (totalBold) {
341
- receiptText.append((char) 0x1B).append((char) 0x45).append((char) 0x00); // Bold off
342
- }
343
- }
344
-
345
- // Footer
346
- if (template.has("footer")) {
347
- // Get footer formatting
348
- byte footerSizeCode = 0x00;
349
- if (template.has("formatting")) {
350
- JSObject formatting = template.getJSObject("formatting");
351
- if (formatting != null && formatting.has("footerSize")) {
352
- footerSizeCode = mapHeaderSizeToCode(formatting.get("footerSize"));
353
- }
354
- }
355
-
356
- // Apply footer formatting
357
- if (footerSizeCode != 0x00) {
358
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) footerSizeCode); // Set size
359
- }
360
-
361
- receiptText.append(template.getString("footer")).append("\n");
362
-
363
- // Reset footer formatting
364
- if (footerSizeCode != 0x00) {
365
- receiptText.append((char) 0x1D).append((char) 0x21).append((char) 0x00); // Normal size
366
- }
367
- }
368
-
369
- // Line feeds and cut
370
- receiptText.append("\n\n\n");
371
- receiptText.append("\u001D\u0056\u0041\u0010"); // Cut command
372
-
373
- return receiptText.toString().getBytes("UTF-8");
374
- } catch (Exception e) {
375
- Log.e(TAG, "Error formatting receipt", e);
376
- return new byte[0];
377
- }
378
- }
379
-
380
- private byte mapHeaderSizeToCode(Object size) {
381
- if (size instanceof Integer) {
382
- int sizeInt = (Integer) size;
383
- switch (sizeInt) {
384
- case 1: return 0x00;
385
- case 2: return 0x11;
386
- case 3: return 0x22;
387
- case 4: return 0x33;
388
- default: return 0x00;
389
- }
390
- } else if (size instanceof String) {
391
- String sizeStr = (String) size;
392
- switch (sizeStr) {
393
- case "normal": return 0x00;
394
- case "large": return 0x11;
395
- case "xlarge": return 0x22;
396
- default: return 0x00;
397
- }
398
- }
399
- return 0x00;
400
- }
401
-
402
- private static class PrinterConnection {
403
- private BluetoothSocket bluetoothSocket;
404
- private Socket wifiSocket;
405
- private OutputStream outputStream;
406
-
407
- public boolean connectBluetooth(BluetoothDevice device) {
408
- try {
409
- // UUID for printer service (this might need to be specific to Zywell)
410
- UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
411
- bluetoothSocket = device.createRfcommSocketToServiceRecord(uuid);
412
- bluetoothSocket.connect();
413
- outputStream = bluetoothSocket.getOutputStream();
414
- return true;
415
- } catch (Exception e) {
416
- Log.e(TAG, "Bluetooth connection failed", e);
417
- return false;
418
- }
419
- }
420
-
421
- public boolean connectWiFi(String ipAddress, int port) {
422
- try {
423
- wifiSocket = new Socket(ipAddress, port);
424
- outputStream = wifiSocket.getOutputStream();
425
- return true;
426
- } catch (Exception e) {
427
- Log.e(TAG, "WiFi connection failed", e);
428
- return false;
429
- }
430
- }
431
-
432
- public boolean sendData(byte[] data) {
433
- try {
434
- if (outputStream != null) {
435
- outputStream.write(data);
436
- outputStream.flush();
437
- return true;
438
- }
439
- } catch (IOException e) {
440
- Log.e(TAG, "Error sending data", e);
441
- }
442
- return false;
443
- }
444
-
445
- public void disconnect() {
446
- try {
447
- if (outputStream != null) {
448
- outputStream.close();
449
- }
450
- if (bluetoothSocket != null) {
451
- bluetoothSocket.close();
452
- }
453
- if (wifiSocket != null) {
454
- wifiSocket.close();
455
- }
456
- } catch (IOException e) {
457
- Log.e(TAG, "Error disconnecting", e);
458
- }
459
- }
460
- }
461
- }
@@ -1,161 +0,0 @@
1
- package com.mycompany.plugins.example;
2
-
3
- import com.getcapacitor.JSArray;
4
- import com.getcapacitor.JSObject;
5
- import com.getcapacitor.Plugin;
6
- import com.getcapacitor.PluginCall;
7
- import com.getcapacitor.PluginMethod;
8
- import com.getcapacitor.annotation.CapacitorPlugin;
9
-
10
- @CapacitorPlugin(name = "Zyprint")
11
- public class ZyprintPlugin extends Plugin {
12
-
13
- private Zyprint implementation = new Zyprint();
14
-
15
- @PluginMethod
16
- public void echo(PluginCall call) {
17
- String value = call.getString("value");
18
-
19
- JSObject ret = new JSObject();
20
- ret.put("value", implementation.echo(value));
21
- call.resolve(ret);
22
- }
23
-
24
- @PluginMethod
25
- public void discoverPrinters(PluginCall call) {
26
- implementation.discoverPrinters(new Zyprint.PrinterDiscoveryCallback() {
27
- @Override
28
- public void onPrintersFound(JSArray printers) {
29
- JSObject ret = new JSObject();
30
- ret.put("printers", printers);
31
- call.resolve(ret);
32
- }
33
-
34
- @Override
35
- public void onError(String error) {
36
- call.reject(error);
37
- }
38
- });
39
- }
40
-
41
- @PluginMethod
42
- public void connectToPrinter(PluginCall call) {
43
- String identifier = call.getString("identifier");
44
- if (identifier == null) {
45
- call.reject("Missing identifier parameter");
46
- return;
47
- }
48
-
49
- implementation.connectToPrinter(identifier, new Zyprint.ConnectionCallback() {
50
- @Override
51
- public void onConnected() {
52
- JSObject ret = new JSObject();
53
- ret.put("connected", true);
54
- call.resolve(ret);
55
- }
56
-
57
- @Override
58
- public void onError(String error) {
59
- call.reject(error);
60
- }
61
- });
62
- }
63
-
64
- @PluginMethod
65
- public void disconnectFromPrinter(PluginCall call) {
66
- String identifier = call.getString("identifier");
67
- if (identifier == null) {
68
- call.reject("Missing identifier parameter");
69
- return;
70
- }
71
-
72
- implementation.disconnectFromPrinter(identifier, new Zyprint.DisconnectionCallback() {
73
- @Override
74
- public void onDisconnected() {
75
- JSObject ret = new JSObject();
76
- ret.put("disconnected", true);
77
- call.resolve(ret);
78
- }
79
-
80
- @Override
81
- public void onError(String error) {
82
- call.reject(error);
83
- }
84
- });
85
- }
86
-
87
- @PluginMethod
88
- public void printText(PluginCall call) {
89
- String text = call.getString("text");
90
- String identifier = call.getString("identifier");
91
-
92
- if (text == null || identifier == null) {
93
- call.reject("Missing required parameters");
94
- return;
95
- }
96
-
97
- implementation.printText(text, identifier, new Zyprint.PrintCallback() {
98
- @Override
99
- public void onSuccess() {
100
- JSObject ret = new JSObject();
101
- ret.put("success", true);
102
- call.resolve(ret);
103
- }
104
-
105
- @Override
106
- public void onError(String error) {
107
- call.reject(error);
108
- }
109
- });
110
- }
111
-
112
- @PluginMethod
113
- public void printReceipt(PluginCall call) {
114
- JSObject template = call.getObject("template");
115
- String identifier = call.getString("identifier");
116
-
117
- if (template == null || identifier == null) {
118
- call.reject("Missing required parameters");
119
- return;
120
- }
121
-
122
- implementation.printReceipt(template, identifier, new Zyprint.PrintCallback() {
123
- @Override
124
- public void onSuccess() {
125
- JSObject ret = new JSObject();
126
- ret.put("success", true);
127
- call.resolve(ret);
128
- }
129
-
130
- @Override
131
- public void onError(String error) {
132
- call.reject(error);
133
- }
134
- });
135
- }
136
-
137
- @PluginMethod
138
- public void getPrinterStatus(PluginCall call) {
139
- String identifier = call.getString("identifier");
140
- if (identifier == null) {
141
- call.reject("Missing identifier parameter");
142
- return;
143
- }
144
-
145
- implementation.getPrinterStatus(identifier, new Zyprint.StatusCallback() {
146
- @Override
147
- public void onStatus(String status, String paperStatus, boolean connected) {
148
- JSObject ret = new JSObject();
149
- ret.put("status", status);
150
- ret.put("paperStatus", paperStatus);
151
- ret.put("connected", connected);
152
- call.resolve(ret);
153
- }
154
-
155
- @Override
156
- public void onError(String error) {
157
- call.reject(error);
158
- }
159
- });
160
- }
161
- }
File without changes