@posx/capacitor-usb-printer 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -1,16 +1,16 @@
1
- # @posx/capacitor-usb-printer
2
-
3
- Capacitor plugin for
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @posx/capacitor-usb-printer
9
- npx cap sync
10
- ```
11
-
12
- ## API
13
-
1
+ # @posx/capacitor-usb-printer
2
+
3
+ Capacitor plugin for
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @posx/capacitor-usb-printer
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
14
  <docgen-index>
15
15
 
16
16
  * [`listDevices()`](#listdevices)
@@ -19,10 +19,12 @@ npx cap sync
19
19
  * [`disconnect(...)`](#disconnect)
20
20
  * [`print(...)`](#print)
21
21
  * [`getStatus(...)`](#getstatus)
22
+ * [`addListener('deviceAttached', ...)`](#addlistenerdeviceattached-)
23
+ * [`addListener('deviceDetached', ...)`](#addlistenerdevicedetached-)
22
24
  * [Interfaces](#interfaces)
23
25
 
24
- </docgen-index>
25
-
26
+ </docgen-index>
27
+
26
28
  <docgen-api>
27
29
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
28
30
 
@@ -108,6 +110,38 @@ getStatus(options: { deviceId: number; }) => Promise<{ connected: boolean; devic
108
110
  --------------------
109
111
 
110
112
 
113
+ ### addListener('deviceAttached', ...)
114
+
115
+ ```typescript
116
+ addListener(eventName: 'deviceAttached', listenerFunc: (device: UsbDevice) => void) => Promise<PluginListenerHandle>
117
+ ```
118
+
119
+ | Param | Type |
120
+ | ------------------ | -------------------------------------------------------------------- |
121
+ | **`eventName`** | <code>'deviceAttached'</code> |
122
+ | **`listenerFunc`** | <code>(device: <a href="#usbdevice">UsbDevice</a>) =&gt; void</code> |
123
+
124
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
125
+
126
+ --------------------
127
+
128
+
129
+ ### addListener('deviceDetached', ...)
130
+
131
+ ```typescript
132
+ addListener(eventName: 'deviceDetached', listenerFunc: (device: UsbDevice) => void) => Promise<PluginListenerHandle>
133
+ ```
134
+
135
+ | Param | Type |
136
+ | ------------------ | -------------------------------------------------------------------- |
137
+ | **`eventName`** | <code>'deviceDetached'</code> |
138
+ | **`listenerFunc`** | <code>(device: <a href="#usbdevice">UsbDevice</a>) =&gt; void</code> |
139
+
140
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
141
+
142
+ --------------------
143
+
144
+
111
145
  ### Interfaces
112
146
 
113
147
 
@@ -123,4 +157,11 @@ getStatus(options: { deviceId: number; }) => Promise<{ connected: boolean; devic
123
157
  | **`productName`** | <code>string</code> |
124
158
  | **`serialNumber`** | <code>string</code> |
125
159
 
126
- </docgen-api>
160
+
161
+ #### PluginListenerHandle
162
+
163
+ | Prop | Type |
164
+ | ------------ | ----------------------------------------- |
165
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
166
+
167
+ </docgen-api>
@@ -1,58 +1,58 @@
1
- ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
- }
7
-
8
- buildscript {
9
- repositories {
10
- google()
11
- mavenCentral()
12
- }
13
- dependencies {
14
- classpath 'com.android.tools.build:gradle:8.13.0'
15
- }
16
- }
17
-
18
- apply plugin: 'com.android.library'
19
-
20
- android {
21
- namespace = "ai.posx.capacitor.usbprinter"
22
- compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
- defaultConfig {
24
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
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
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "ai.posx.capacitor.usbprinter"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
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,4 +1,4 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
- <uses-feature android:name="android.hardware.usb.host" android:required="false" />
4
- </manifest>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <uses-feature android:name="android.hardware.usb.host" android:required="false" />
4
+ </manifest>
@@ -1,179 +1,179 @@
1
- package ai.posx.capacitor.usbprinter;
2
-
3
- import android.app.PendingIntent;
4
- import android.content.BroadcastReceiver;
5
- import android.content.Context;
6
- import android.content.Intent;
7
- import android.content.IntentFilter;
8
- import android.hardware.usb.*;
9
- import android.os.Build;
10
- import android.util.Log;
11
-
12
- import java.util.ArrayList;
13
- import java.util.HashMap;
14
- import java.util.List;
15
- import java.util.Map;
16
- import java.util.concurrent.ConcurrentHashMap;
17
-
18
- public class UsbPrinter {
19
- private static final String TAG = "UsbPrinter";
20
- private static final String ACTION_USB_PERMISSION = "ai.posx.capacitor.usbprinter.USB_PERMISSION";
21
-
22
- private final UsbManager usbManager;
23
- private final Map<Integer, DeviceConnection> connections = new ConcurrentHashMap<>();
24
-
25
- public UsbPrinter(Context context) {
26
- usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
27
- }
28
-
29
- public List<UsbDevice> listDevices() {
30
- return new ArrayList<>(usbManager.getDeviceList().values());
31
- }
32
-
33
- public String getSerialNumber(UsbDevice device) {
34
- try {
35
- return device.getSerialNumber() != null ? device.getSerialNumber() : "";
36
- } catch (SecurityException e) {
37
- return "";
38
- }
39
- }
40
-
41
- public void requestPermission(Context context, UsbDevice device, PermissionCallback callback) {
42
- if (usbManager.hasPermission(device)) {
43
- callback.onResult(true);
44
- return;
45
- }
46
-
47
- BroadcastReceiver receiver = new BroadcastReceiver() {
48
- @Override
49
- public void onReceive(Context ctx, Intent intent) {
50
- context.unregisterReceiver(this);
51
- boolean granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
52
- callback.onResult(granted);
53
- }
54
- };
55
-
56
- IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
57
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
58
- context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
59
- } else {
60
- context.registerReceiver(receiver, filter);
61
- }
62
-
63
- int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0;
64
- PendingIntent pi = PendingIntent.getBroadcast(context, device.getDeviceId(), new Intent(ACTION_USB_PERMISSION), flags);
65
- usbManager.requestPermission(device, pi);
66
- }
67
-
68
- public boolean connect(UsbDevice device) {
69
- int id = device.getDeviceId();
70
- if (connections.containsKey(id)) return true;
71
-
72
- UsbEndpoint bulkOut = null;
73
- UsbInterface usbInterface = null;
74
-
75
- for (int i = 0; i < device.getInterfaceCount(); i++) {
76
- UsbInterface iface = device.getInterface(i);
77
- for (int j = 0; j < iface.getEndpointCount(); j++) {
78
- UsbEndpoint ep = iface.getEndpoint(j);
79
- if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && ep.getDirection() == UsbConstants.USB_DIR_OUT) {
80
- usbInterface = iface;
81
- bulkOut = ep;
82
- break;
83
- }
84
- }
85
- if (bulkOut != null) break;
86
- }
87
-
88
- if (bulkOut == null) {
89
- Log.e(TAG, "No bulk OUT endpoint found for device " + id);
90
- return false;
91
- }
92
-
93
- UsbDeviceConnection conn = usbManager.openDevice(device);
94
- if (conn == null) {
95
- Log.e(TAG, "Failed to open device " + id);
96
- return false;
97
- }
98
-
99
- try {
100
- conn.claimInterface(usbInterface, true);
101
- String name = device.getProductName() != null ? device.getProductName() : device.getDeviceName();
102
- String serial = getSerialNumber(device);
103
- connections.put(id, new DeviceConnection(conn, bulkOut, usbInterface, name, serial));
104
- return true;
105
- } catch (Exception e) {
106
- conn.close();
107
- Log.e(TAG, "Failed to claim interface for device " + id, e);
108
- return false;
109
- }
110
- }
111
-
112
- public void disconnect(int deviceId) {
113
- DeviceConnection dc = connections.remove(deviceId);
114
- if (dc != null) dc.close();
115
- }
116
-
117
- public void disconnectAll() {
118
- for (DeviceConnection dc : connections.values()) {
119
- try { dc.close(); } catch (Exception e) { Log.e(TAG, "Failed to close connection", e); }
120
- }
121
- connections.clear();
122
- }
123
-
124
- public boolean print(int deviceId, byte[] data) {
125
- DeviceConnection dc = connections.get(deviceId);
126
- if (dc == null) return false;
127
- int result = dc.connection.bulkTransfer(dc.bulkOut, data, data.length, 10000);
128
- if (result < 0) Log.e(TAG, "Transfer failed for device " + deviceId + ": " + result);
129
- return result >= 0;
130
- }
131
-
132
- public boolean isConnected(int deviceId) {
133
- return connections.containsKey(deviceId);
134
- }
135
-
136
- public DeviceConnection getConnection(int deviceId) {
137
- return connections.get(deviceId);
138
- }
139
-
140
- public UsbDevice findDevice(int deviceId) {
141
- for (UsbDevice device : usbManager.getDeviceList().values()) {
142
- if (device.getDeviceId() == deviceId) return device;
143
- }
144
- return null;
145
- }
146
-
147
- public static byte[] hexToBytes(String hex) {
148
- int len = hex.length();
149
- byte[] data = new byte[len / 2];
150
- for (int i = 0; i < len; i += 2) {
151
- data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
152
- }
153
- return data;
154
- }
155
-
156
- public interface PermissionCallback {
157
- void onResult(boolean granted);
158
- }
159
-
160
- public static class DeviceConnection {
161
- public final UsbDeviceConnection connection;
162
- public final UsbEndpoint bulkOut;
163
- public final UsbInterface usbInterface;
164
- public final String deviceName;
165
- public final String serialNumber;
166
-
167
- DeviceConnection(UsbDeviceConnection connection, UsbEndpoint bulkOut, UsbInterface usbInterface, String deviceName, String serialNumber) {
168
- this.connection = connection;
169
- this.bulkOut = bulkOut;
170
- this.usbInterface = usbInterface;
171
- this.deviceName = deviceName;
172
- this.serialNumber = serialNumber;
173
- }
174
-
175
- void close() {
176
- try { connection.releaseInterface(usbInterface); } finally { connection.close(); }
177
- }
178
- }
179
- }
1
+ package ai.posx.capacitor.usbprinter;
2
+
3
+ import android.app.PendingIntent;
4
+ import android.content.BroadcastReceiver;
5
+ import android.content.Context;
6
+ import android.content.Intent;
7
+ import android.content.IntentFilter;
8
+ import android.hardware.usb.*;
9
+ import android.os.Build;
10
+ import android.util.Log;
11
+
12
+ import java.util.ArrayList;
13
+ import java.util.List;
14
+ import java.util.Map;
15
+ import java.util.concurrent.ConcurrentHashMap;
16
+
17
+ public class UsbPrinter {
18
+ private static final String TAG = "UsbPrinter";
19
+ private static final String ACTION_USB_PERMISSION = "ai.posx.capacitor.usbprinter.USB_PERMISSION";
20
+
21
+ private final UsbManager usbManager;
22
+ private final Map<Integer, DeviceConnection> connections = new ConcurrentHashMap<>();
23
+ private final Map<Integer, BroadcastReceiver> pendingPermissions = new ConcurrentHashMap<>();
24
+
25
+ public UsbPrinter(Context context) {
26
+ usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
27
+ }
28
+
29
+ public List<UsbDevice> listDevices() {
30
+ return new ArrayList<>(usbManager.getDeviceList().values());
31
+ }
32
+
33
+ public String getSerialNumber(UsbDevice device) {
34
+ try {
35
+ return device.getSerialNumber() != null ? device.getSerialNumber() : "";
36
+ } catch (SecurityException e) {
37
+ return "";
38
+ }
39
+ }
40
+
41
+ public void requestPermission(Context context, UsbDevice device, PermissionCallback callback) {
42
+ if (usbManager.hasPermission(device)) {
43
+ callback.onResult(true);
44
+ return;
45
+ }
46
+ int deviceId = device.getDeviceId();
47
+ BroadcastReceiver receiver = new BroadcastReceiver() {
48
+ @Override
49
+ public void onReceive(Context ctx, Intent intent) {
50
+ pendingPermissions.remove(deviceId);
51
+ context.unregisterReceiver(this);
52
+ callback.onResult(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false));
53
+ }
54
+ };
55
+ pendingPermissions.put(deviceId, receiver);
56
+ IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
57
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
58
+ context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
59
+ else
60
+ context.registerReceiver(receiver, filter);
61
+ int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0;
62
+ PendingIntent pi = PendingIntent.getBroadcast(context, deviceId, new Intent(ACTION_USB_PERMISSION), flags);
63
+ usbManager.requestPermission(device, pi);
64
+ }
65
+
66
+ public void releasePermissionReceivers(Context context) {
67
+ for (BroadcastReceiver r : pendingPermissions.values())
68
+ try { context.unregisterReceiver(r); } catch (Exception ignored) {}
69
+ pendingPermissions.clear();
70
+ }
71
+
72
+ public boolean connect(UsbDevice device) {
73
+ int id = device.getDeviceId();
74
+ if (connections.containsKey(id)) return true;
75
+
76
+ UsbEndpoint bulkOut = null;
77
+ UsbInterface usbInterface = null;
78
+
79
+ for (int i = 0; i < device.getInterfaceCount(); i++) {
80
+ UsbInterface iface = device.getInterface(i);
81
+ for (int j = 0; j < iface.getEndpointCount(); j++) {
82
+ UsbEndpoint ep = iface.getEndpoint(j);
83
+ if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && ep.getDirection() == UsbConstants.USB_DIR_OUT) {
84
+ usbInterface = iface;
85
+ bulkOut = ep;
86
+ break;
87
+ }
88
+ }
89
+ if (bulkOut != null) break;
90
+ }
91
+
92
+ if (bulkOut == null) {
93
+ Log.e(TAG, "No bulk OUT endpoint found for device " + id);
94
+ return false;
95
+ }
96
+
97
+ UsbDeviceConnection conn = usbManager.openDevice(device);
98
+ if (conn == null) {
99
+ Log.e(TAG, "Failed to open device " + id);
100
+ return false;
101
+ }
102
+
103
+ try {
104
+ conn.claimInterface(usbInterface, true);
105
+ String name = device.getProductName() != null ? device.getProductName() : device.getDeviceName();
106
+ String serial = getSerialNumber(device);
107
+ connections.put(id, new DeviceConnection(conn, bulkOut, usbInterface, name, serial));
108
+ return true;
109
+ } catch (Exception e) {
110
+ conn.close();
111
+ Log.e(TAG, "Failed to claim interface for device " + id, e);
112
+ return false;
113
+ }
114
+ }
115
+
116
+ public void disconnect(int deviceId) {
117
+ DeviceConnection dc = connections.remove(deviceId);
118
+ if (dc != null) dc.close();
119
+ }
120
+
121
+ public void disconnectAll() {
122
+ for (DeviceConnection dc : connections.values()) {
123
+ try { dc.close(); } catch (Exception e) { Log.e(TAG, "Failed to close connection", e); }
124
+ }
125
+ connections.clear();
126
+ }
127
+
128
+ public boolean print(int deviceId, byte[] data) {
129
+ DeviceConnection dc = connections.get(deviceId);
130
+ if (dc == null) return false;
131
+ int result = dc.connection.bulkTransfer(dc.bulkOut, data, data.length, 10000);
132
+ if (result < 0) Log.e(TAG, "Transfer failed for device " + deviceId + ": " + result);
133
+ return result >= 0;
134
+ }
135
+
136
+ public DeviceConnection getConnection(int deviceId) {
137
+ return connections.get(deviceId);
138
+ }
139
+
140
+ public UsbDevice findDevice(int deviceId) {
141
+ for (UsbDevice device : usbManager.getDeviceList().values()) {
142
+ if (device.getDeviceId() == deviceId) return device;
143
+ }
144
+ return null;
145
+ }
146
+
147
+ public static byte[] hexToBytes(String hex) {
148
+ if (hex.length() % 2 != 0) throw new IllegalArgumentException("Hex string length must be even");
149
+ int len = hex.length();
150
+ byte[] data = new byte[len / 2];
151
+ for (int i = 0; i < len; i += 2)
152
+ data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
153
+ return data;
154
+ }
155
+
156
+ public interface PermissionCallback {
157
+ void onResult(boolean granted);
158
+ }
159
+
160
+ public static class DeviceConnection {
161
+ public final UsbDeviceConnection connection;
162
+ public final UsbEndpoint bulkOut;
163
+ public final UsbInterface usbInterface;
164
+ public final String deviceName;
165
+ public final String serialNumber;
166
+
167
+ DeviceConnection(UsbDeviceConnection connection, UsbEndpoint bulkOut, UsbInterface usbInterface, String deviceName, String serialNumber) {
168
+ this.connection = connection;
169
+ this.bulkOut = bulkOut;
170
+ this.usbInterface = usbInterface;
171
+ this.deviceName = deviceName;
172
+ this.serialNumber = serialNumber;
173
+ }
174
+
175
+ void close() {
176
+ try { connection.releaseInterface(usbInterface); } finally { connection.close(); }
177
+ }
178
+ }
179
+ }
@@ -1,138 +1,179 @@
1
- package ai.posx.capacitor.usbprinter;
2
-
3
- import android.hardware.usb.UsbDevice;
4
-
5
- import com.getcapacitor.JSArray;
6
- import com.getcapacitor.JSObject;
7
- import com.getcapacitor.Plugin;
8
- import com.getcapacitor.PluginCall;
9
- import com.getcapacitor.PluginMethod;
10
- import com.getcapacitor.annotation.CapacitorPlugin;
11
-
12
- import java.util.List;
13
-
14
- @CapacitorPlugin(name = "UsbPrinter")
15
- public class UsbPrinterPlugin extends Plugin {
16
-
17
- private UsbPrinter implementation;
18
-
19
- @Override
20
- public void load() {
21
- implementation = new UsbPrinter(getContext());
22
- }
23
-
24
- @Override
25
- protected void handleOnDestroy() {
26
- implementation.disconnectAll();
27
- super.handleOnDestroy();
28
- }
29
-
30
- @PluginMethod
31
- public void listDevices(PluginCall call) {
32
- try {
33
- List<UsbDevice> devices = implementation.listDevices();
34
- JSArray arr = new JSArray();
35
- for (UsbDevice device : devices) {
36
- JSObject d = new JSObject();
37
- d.put("deviceId", device.getDeviceId());
38
- d.put("vendorId", device.getVendorId());
39
- d.put("productId", device.getProductId());
40
- d.put("deviceName", device.getDeviceName());
41
- d.put("manufacturerName", device.getManufacturerName() != null ? device.getManufacturerName() : "");
42
- d.put("productName", device.getProductName() != null ? device.getProductName() : "");
43
- d.put("serialNumber", implementation.getSerialNumber(device));
44
- arr.put(d);
45
- }
46
- JSObject result = new JSObject();
47
- result.put("devices", arr);
48
- call.resolve(result);
49
- } catch (Exception e) {
50
- call.reject("Failed to list devices", e);
51
- }
52
- }
53
-
54
- @PluginMethod
55
- public void requestPermission(PluginCall call) {
56
- try {
57
- int deviceId = call.getInt("deviceId", -1);
58
- UsbDevice device = implementation.findDevice(deviceId);
59
- if (device == null) {
60
- call.reject("Device not found");
61
- return;
62
- }
63
- implementation.requestPermission(getContext(), device, granted -> {
64
- JSObject result = new JSObject();
65
- result.put("granted", granted);
66
- call.resolve(result);
67
- });
68
- } catch (Exception e) {
69
- call.reject("Failed to request permission", e);
70
- }
71
- }
72
-
73
- @PluginMethod
74
- public void connect(PluginCall call) {
75
- try {
76
- int deviceId = call.getInt("deviceId", -1);
77
- UsbDevice device = implementation.findDevice(deviceId);
78
- if (device == null) {
79
- call.reject("Device not found");
80
- return;
81
- }
82
- boolean connected = implementation.connect(device);
83
- if (!connected) {
84
- call.reject("Failed to connect");
85
- return;
86
- }
87
- JSObject result = new JSObject();
88
- result.put("connected", true);
89
- call.resolve(result);
90
- } catch (Exception e) {
91
- call.reject("Failed to connect", e);
92
- }
93
- }
94
-
95
- @PluginMethod
96
- public void disconnect(PluginCall call) {
97
- try {
98
- int deviceId = call.getInt("deviceId", -1);
99
- implementation.disconnect(deviceId);
100
- call.resolve();
101
- } catch (Exception e) {
102
- call.reject("Failed to disconnect", e);
103
- }
104
- }
105
-
106
- @PluginMethod
107
- public void print(PluginCall call) {
108
- try {
109
- int deviceId = call.getInt("deviceId", -1);
110
- String hex = call.getString("data", "");
111
- if (hex.isEmpty()) {
112
- call.reject("No data");
113
- return;
114
- }
115
- byte[] bytes = UsbPrinter.hexToBytes(hex);
116
- boolean success = implementation.print(deviceId, bytes);
117
- if (success) call.resolve();
118
- else call.reject("Not connected or transfer failed");
119
- } catch (Exception e) {
120
- call.reject("Failed to print", e);
121
- }
122
- }
123
-
124
- @PluginMethod
125
- public void getStatus(PluginCall call) {
126
- try {
127
- int deviceId = call.getInt("deviceId", -1);
128
- UsbPrinter.DeviceConnection dc = implementation.getConnection(deviceId);
129
- JSObject result = new JSObject();
130
- result.put("connected", dc != null);
131
- result.put("deviceName", dc != null ? dc.deviceName : "");
132
- result.put("serialNumber", dc != null ? dc.serialNumber : "");
133
- call.resolve(result);
134
- } catch (Exception e) {
135
- call.reject("Failed to get status", e);
136
- }
137
- }
138
- }
1
+ package ai.posx.capacitor.usbprinter;
2
+
3
+ import android.content.BroadcastReceiver;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.content.IntentFilter;
7
+ import android.hardware.usb.UsbDevice;
8
+ import android.hardware.usb.UsbManager;
9
+ import android.os.Build;
10
+
11
+ import com.getcapacitor.JSArray;
12
+ import com.getcapacitor.JSObject;
13
+ import com.getcapacitor.Plugin;
14
+ import com.getcapacitor.PluginCall;
15
+ import com.getcapacitor.PluginMethod;
16
+ import com.getcapacitor.annotation.CapacitorPlugin;
17
+
18
+ import java.util.List;
19
+
20
+ @CapacitorPlugin(name = "UsbPrinter")
21
+ public class UsbPrinterPlugin extends Plugin {
22
+
23
+ private UsbPrinter implementation;
24
+ private BroadcastReceiver usbReceiver;
25
+
26
+ @Override
27
+ public void load() {
28
+ implementation = new UsbPrinter(getContext());
29
+ usbReceiver = new BroadcastReceiver() {
30
+ @Override
31
+ public void onReceive(Context ctx, Intent intent) {
32
+ UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
33
+ if (device == null) return;
34
+ JSObject data = deviceToJs(device);
35
+ if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(intent.getAction())) {
36
+ UsbPrinter.DeviceConnection dc = implementation.getConnection(device.getDeviceId());
37
+ data.put("serialNumber", dc != null ? dc.serialNumber : implementation.getSerialNumber(device));
38
+ implementation.disconnect(device.getDeviceId());
39
+ notifyListeners("deviceDetached", data);
40
+ } else {
41
+ data.put("serialNumber", implementation.getSerialNumber(device));
42
+ notifyListeners("deviceAttached", data);
43
+ }
44
+ }
45
+ };
46
+ IntentFilter filter = new IntentFilter();
47
+ filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
48
+ filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
49
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
50
+ getContext().registerReceiver(usbReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
51
+ else
52
+ getContext().registerReceiver(usbReceiver, filter);
53
+ }
54
+
55
+ @Override
56
+ protected void handleOnDestroy() {
57
+ if (usbReceiver != null) {
58
+ getContext().unregisterReceiver(usbReceiver);
59
+ usbReceiver = null;
60
+ }
61
+ implementation.releasePermissionReceivers(getContext());
62
+ implementation.disconnectAll();
63
+ super.handleOnDestroy();
64
+ }
65
+
66
+ private JSObject deviceToJs(UsbDevice device) {
67
+ JSObject d = new JSObject();
68
+ d.put("deviceId", device.getDeviceId());
69
+ d.put("vendorId", device.getVendorId());
70
+ d.put("productId", device.getProductId());
71
+ d.put("deviceName", device.getDeviceName());
72
+ d.put("manufacturerName", device.getManufacturerName() != null ? device.getManufacturerName() : "");
73
+ d.put("productName", device.getProductName() != null ? device.getProductName() : "");
74
+ return d;
75
+ }
76
+
77
+ @PluginMethod
78
+ public void listDevices(PluginCall call) {
79
+ try {
80
+ List<UsbDevice> devices = implementation.listDevices();
81
+ JSArray arr = new JSArray();
82
+ for (UsbDevice device : devices) {
83
+ JSObject d = deviceToJs(device);
84
+ d.put("serialNumber", implementation.getSerialNumber(device));
85
+ arr.put(d);
86
+ }
87
+ JSObject result = new JSObject();
88
+ result.put("devices", arr);
89
+ call.resolve(result);
90
+ } catch (Exception e) {
91
+ call.reject("Failed to list devices", e);
92
+ }
93
+ }
94
+
95
+ @PluginMethod
96
+ public void requestPermission(PluginCall call) {
97
+ try {
98
+ int deviceId = call.getInt("deviceId", -1);
99
+ UsbDevice device = implementation.findDevice(deviceId);
100
+ if (device == null) {
101
+ call.reject("Device not found");
102
+ return;
103
+ }
104
+ implementation.requestPermission(getContext(), device, granted -> {
105
+ JSObject result = new JSObject();
106
+ result.put("granted", granted);
107
+ call.resolve(result);
108
+ });
109
+ } catch (Exception e) {
110
+ call.reject("Failed to request permission", e);
111
+ }
112
+ }
113
+
114
+ @PluginMethod
115
+ public void connect(PluginCall call) {
116
+ try {
117
+ int deviceId = call.getInt("deviceId", -1);
118
+ UsbDevice device = implementation.findDevice(deviceId);
119
+ if (device == null) {
120
+ call.reject("Device not found");
121
+ return;
122
+ }
123
+ boolean connected = implementation.connect(device);
124
+ if (!connected) {
125
+ call.reject("Failed to connect");
126
+ return;
127
+ }
128
+ JSObject result = new JSObject();
129
+ result.put("connected", true);
130
+ call.resolve(result);
131
+ } catch (Exception e) {
132
+ call.reject("Failed to connect", e);
133
+ }
134
+ }
135
+
136
+ @PluginMethod
137
+ public void disconnect(PluginCall call) {
138
+ try {
139
+ int deviceId = call.getInt("deviceId", -1);
140
+ implementation.disconnect(deviceId);
141
+ call.resolve();
142
+ } catch (Exception e) {
143
+ call.reject("Failed to disconnect", e);
144
+ }
145
+ }
146
+
147
+ @PluginMethod
148
+ public void print(PluginCall call) {
149
+ try {
150
+ int deviceId = call.getInt("deviceId", -1);
151
+ String hex = call.getString("data", "");
152
+ if (hex.isEmpty()) {
153
+ call.reject("No data");
154
+ return;
155
+ }
156
+ byte[] bytes = UsbPrinter.hexToBytes(hex);
157
+ boolean success = implementation.print(deviceId, bytes);
158
+ if (success) call.resolve();
159
+ else call.reject("Not connected or transfer failed");
160
+ } catch (Exception e) {
161
+ call.reject("Failed to print", e);
162
+ }
163
+ }
164
+
165
+ @PluginMethod
166
+ public void getStatus(PluginCall call) {
167
+ try {
168
+ int deviceId = call.getInt("deviceId", -1);
169
+ UsbPrinter.DeviceConnection dc = implementation.getConnection(deviceId);
170
+ JSObject result = new JSObject();
171
+ result.put("connected", dc != null);
172
+ result.put("deviceName", dc != null ? dc.deviceName : "");
173
+ result.put("serialNumber", dc != null ? dc.serialNumber : "");
174
+ call.resolve(result);
175
+ } catch (Exception e) {
176
+ call.reject("Failed to get status", e);
177
+ }
178
+ }
179
+ }
@@ -1,4 +1,4 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <resources>
3
- <usb-device />
4
- </resources>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <usb-device />
4
+ </resources>
package/dist/docs.json CHANGED
@@ -96,6 +96,54 @@
96
96
  "docs": "",
97
97
  "complexTypes": [],
98
98
  "slug": "getstatus"
99
+ },
100
+ {
101
+ "name": "addListener",
102
+ "signature": "(eventName: 'deviceAttached', listenerFunc: (device: UsbDevice) => void) => Promise<PluginListenerHandle>",
103
+ "parameters": [
104
+ {
105
+ "name": "eventName",
106
+ "docs": "",
107
+ "type": "'deviceAttached'"
108
+ },
109
+ {
110
+ "name": "listenerFunc",
111
+ "docs": "",
112
+ "type": "(device: UsbDevice) => void"
113
+ }
114
+ ],
115
+ "returns": "Promise<PluginListenerHandle>",
116
+ "tags": [],
117
+ "docs": "",
118
+ "complexTypes": [
119
+ "PluginListenerHandle",
120
+ "UsbDevice"
121
+ ],
122
+ "slug": "addlistenerdeviceattached-"
123
+ },
124
+ {
125
+ "name": "addListener",
126
+ "signature": "(eventName: 'deviceDetached', listenerFunc: (device: UsbDevice) => void) => Promise<PluginListenerHandle>",
127
+ "parameters": [
128
+ {
129
+ "name": "eventName",
130
+ "docs": "",
131
+ "type": "'deviceDetached'"
132
+ },
133
+ {
134
+ "name": "listenerFunc",
135
+ "docs": "",
136
+ "type": "(device: UsbDevice) => void"
137
+ }
138
+ ],
139
+ "returns": "Promise<PluginListenerHandle>",
140
+ "tags": [],
141
+ "docs": "",
142
+ "complexTypes": [
143
+ "PluginListenerHandle",
144
+ "UsbDevice"
145
+ ],
146
+ "slug": "addlistenerdevicedetached-"
99
147
  }
100
148
  ],
101
149
  "properties": []
@@ -158,6 +206,22 @@
158
206
  "type": "string"
159
207
  }
160
208
  ]
209
+ },
210
+ {
211
+ "name": "PluginListenerHandle",
212
+ "slug": "pluginlistenerhandle",
213
+ "docs": "",
214
+ "tags": [],
215
+ "methods": [],
216
+ "properties": [
217
+ {
218
+ "name": "remove",
219
+ "tags": [],
220
+ "docs": "",
221
+ "complexTypes": [],
222
+ "type": "() => Promise<void>"
223
+ }
224
+ ]
161
225
  }
162
226
  ],
163
227
  "enums": [],
@@ -1,3 +1,4 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
1
2
  export interface UsbDevice {
2
3
  deviceId: number;
3
4
  vendorId: number;
@@ -35,4 +36,6 @@ export interface UsbPrinterPlugin {
35
36
  deviceName: string;
36
37
  serialNumber: string;
37
38
  }>;
39
+ addListener(eventName: 'deviceAttached', listenerFunc: (device: UsbDevice) => void): Promise<PluginListenerHandle>;
40
+ addListener(eventName: 'deviceDetached', listenerFunc: (device: UsbDevice) => void): Promise<PluginListenerHandle>;
38
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface UsbDevice {\n deviceId: number;\n vendorId: number;\n productId: number;\n deviceName: string;\n manufacturerName: string;\n productName: string;\n serialNumber: string;\n}\n\nexport interface UsbPrinterPlugin {\n listDevices(): Promise<{ devices: UsbDevice[] }>;\n requestPermission(options: { deviceId: number }): Promise<{ granted: boolean }>;\n connect(options: { deviceId: number }): Promise<{ connected: boolean }>;\n disconnect(options: { deviceId: number }): Promise<void>;\n print(options: { deviceId: number; data: string }): Promise<void>;\n getStatus(options: { deviceId: number }): Promise<{ connected: boolean; deviceName: string; serialNumber: string }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\r\n\r\nexport interface UsbDevice {\r\n deviceId: number;\r\n vendorId: number;\r\n productId: number;\r\n deviceName: string;\r\n manufacturerName: string;\r\n productName: string;\r\n serialNumber: string;\r\n}\r\n\r\nexport interface UsbPrinterPlugin {\r\n listDevices(): Promise<{ devices: UsbDevice[] }>;\r\n requestPermission(options: { deviceId: number }): Promise<{ granted: boolean }>;\r\n connect(options: { deviceId: number }): Promise<{ connected: boolean }>;\r\n disconnect(options: { deviceId: number }): Promise<void>;\r\n print(options: { deviceId: number; data: string }): Promise<void>;\r\n getStatus(options: { deviceId: number }): Promise<{ connected: boolean; deviceName: string; serialNumber: string }>;\r\n addListener(eventName: 'deviceAttached', listenerFunc: (device: UsbDevice) => void): Promise<PluginListenerHandle>;\r\n addListener(eventName: 'deviceDetached', listenerFunc: (device: UsbDevice) => void): Promise<PluginListenerHandle>;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { UsbPrinterPlugin } from './definitions';\n\nconst UsbPrinter = registerPlugin<UsbPrinterPlugin>('UsbPrinter', {\n web: () => import('./web').then((m) => new m.UsbPrinterWeb()),\n});\n\nexport * from './definitions';\nexport { UsbPrinter };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\r\n\r\nimport type { UsbPrinterPlugin } from './definitions';\r\n\r\nconst UsbPrinter = registerPlugin<UsbPrinterPlugin>('UsbPrinter', {\r\n web: () => import('./web').then((m) => new m.UsbPrinterWeb()),\r\n});\r\n\r\nexport * from './definitions';\r\nexport { UsbPrinter };\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,WAAW;QACf,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { UsbPrinterPlugin } from './definitions';\n\nexport class UsbPrinterWeb extends WebPlugin implements UsbPrinterPlugin {\n async listDevices(): Promise<{ devices: never[] }> {\n console.warn('USB Printer is only available on Android devices');\n return { devices: [] };\n }\n\n async requestPermission(): Promise<{ granted: boolean }> {\n console.warn('USB Printer is only available on Android devices');\n return { granted: false };\n }\n\n async connect(): Promise<{ connected: boolean }> {\n console.warn('USB Printer is only available on Android devices');\n return { connected: false };\n }\n\n async disconnect(): Promise<void> {\n console.warn('USB Printer is only available on Android devices');\n }\n\n async print(): Promise<void> {\n console.warn('USB Printer is only available on Android devices');\n }\n\n async getStatus(): Promise<{ connected: boolean; deviceName: string; serialNumber: string }> {\n console.warn('USB Printer is only available on Android devices');\n return { connected: false, deviceName: '', serialNumber: '' };\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,WAAW;QACf,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAChE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\r\n\r\nimport type { UsbPrinterPlugin } from './definitions';\r\n\r\nexport class UsbPrinterWeb extends WebPlugin implements UsbPrinterPlugin {\r\n async listDevices(): Promise<{ devices: never[] }> {\r\n console.warn('USB Printer is only available on Android devices');\r\n return { devices: [] };\r\n }\r\n\r\n async requestPermission(): Promise<{ granted: boolean }> {\r\n console.warn('USB Printer is only available on Android devices');\r\n return { granted: false };\r\n }\r\n\r\n async connect(): Promise<{ connected: boolean }> {\r\n console.warn('USB Printer is only available on Android devices');\r\n return { connected: false };\r\n }\r\n\r\n async disconnect(): Promise<void> {\r\n console.warn('USB Printer is only available on Android devices');\r\n }\r\n\r\n async print(): Promise<void> {\r\n console.warn('USB Printer is only available on Android devices');\r\n }\r\n\r\n async getStatus(): Promise<{ connected: boolean; deviceName: string; serialNumber: string }> {\r\n console.warn('USB Printer is only available on Android devices');\r\n return { connected: false, deviceName: '', serialNumber: '' };\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/capacitor-usb-printer",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Capacitor plugin for USB ESC/POS thermal printer via Android USB Host API",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -13,24 +13,34 @@
13
13
  ],
14
14
  "author": "posx team",
15
15
  "license": "MIT",
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/niceit/capacitor-usb-printer.git"
19
- },
20
- "bugs": {
21
- "url": "https://github.com/niceit/capacitor-usb-printer/issues"
22
- },
23
16
  "keywords": [
24
17
  "capacitor",
25
18
  "plugin",
26
19
  "native"
27
20
  ],
21
+ "scripts": {
22
+ "verify": "npm run verify:android && npm run verify:web",
23
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
24
+ "verify:web": "npm run build",
25
+ "lint": "npm run eslint && npm run prettier -- --check",
26
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write",
27
+ "eslint": "eslint . --ext ts",
28
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
29
+ "docgen": "docgen --api UsbPrinterPlugin --output-readme README.md --output-json dist/docs.json",
30
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
31
+ "clean": "rimraf ./dist",
32
+ "p": "npm run build && npm publish",
33
+ "bump": "bumpp patch --commit --tag --push --yes",
34
+ "watch": "tsc --watch",
35
+ "prepublishOnly": "npm run build"
36
+ },
28
37
  "devDependencies": {
29
38
  "@capacitor/android": "^5.7.8",
30
39
  "@capacitor/core": "^5.7.8",
31
40
  "@capacitor/docgen": "^0.3.1",
32
41
  "@ionic/eslint-config": "^0.4.0",
33
42
  "@ionic/prettier-config": "^4.0.0",
43
+ "bumpp": "10.4.1",
34
44
  "eslint": "^8.57.1",
35
45
  "prettier": "^3.6.2",
36
46
  "prettier-plugin-java": "^2.7.7",
@@ -49,20 +59,5 @@
49
59
  "android": {
50
60
  "src": "android"
51
61
  }
52
- },
53
- "scripts": {
54
- "verify": "npm run verify:android && npm run verify:web",
55
- "verify:android": "cd android && ./gradlew clean build test && cd ..",
56
- "verify:web": "npm run build",
57
- "lint": "npm run eslint && npm run prettier -- --check",
58
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write",
59
- "eslint": "eslint . --ext ts",
60
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
61
- "docgen": "docgen --api UsbPrinterPlugin --output-readme README.md --output-json dist/docs.json",
62
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
63
- "clean": "rimraf ./dist",
64
- "p": "npm run build && npm publish",
65
- "bump": "npm version patch",
66
- "watch": "tsc --watch"
67
62
  }
68
- }
63
+ }