@posx/capacitor-usb-printer 0.0.2 → 0.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.
|
@@ -38,8 +38,11 @@ public class UsbPrinterPlugin extends Plugin {
|
|
|
38
38
|
implementation.disconnect(device.getDeviceId());
|
|
39
39
|
notifyListeners("deviceDetached", data);
|
|
40
40
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// request permission first so serialNumber is readable
|
|
42
|
+
implementation.requestPermission(ctx, device, granted -> {
|
|
43
|
+
data.put("serialNumber", implementation.getSerialNumber(device));
|
|
44
|
+
notifyListeners("deviceAttached", data);
|
|
45
|
+
});
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
};
|
|
@@ -52,6 +55,19 @@ public class UsbPrinterPlugin extends Plugin {
|
|
|
52
55
|
getContext().registerReceiver(usbReceiver, filter);
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
@Override
|
|
59
|
+
public void handleOnNewIntent(Intent intent) {
|
|
60
|
+
super.handleOnNewIntent(intent);
|
|
61
|
+
if (!UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) return;
|
|
62
|
+
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
|
63
|
+
if (device == null) return;
|
|
64
|
+
JSObject data = deviceToJs(device);
|
|
65
|
+
implementation.requestPermission(getContext(), device, granted -> {
|
|
66
|
+
data.put("serialNumber", implementation.getSerialNumber(device));
|
|
67
|
+
notifyListeners("deviceAttached", data);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
55
71
|
@Override
|
|
56
72
|
protected void handleOnDestroy() {
|
|
57
73
|
if (usbReceiver != null) {
|
package/package.json
CHANGED