Skip to content

Commit fd80605

Browse files
committed
feat: support multiple instances
BREAKING CHANGE: The open method now returns a printer instance, containing most of the previous methods.
1 parent 9df5c6a commit fd80605

File tree

11 files changed

+2316
-1715
lines changed

11 files changed

+2316
-1715
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Setup
2424
uses: ./.github/actions/setup
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@v3
33+
uses: actions/checkout@v4
3434

3535
- name: Setup
3636
uses: ./.github/actions/setup
@@ -44,7 +44,7 @@ jobs:
4444
runs-on: ubuntu-latest
4545
steps:
4646
- name: Checkout
47-
uses: actions/checkout@v3
47+
uses: actions/checkout@v4
4848

4949
- name: Setup
5050
uses: ./.github/actions/setup

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,20 @@ of methods and their details, you may refer to the PDF manual inside the
2020
```tsx
2121
import {
2222
connect,
23-
cutPaper,
24-
disconnect,
2523
ESCPOSConst,
26-
printText,
2724
searchCitizenPrinters,
2825
} from "react-native-citizen-escposprinter";
2926

3027
const main = async () => {
31-
const printers = await searchCitizenPrinters(
28+
const results = await searchCitizenPrinters(
3229
ESCPOSConst.CMP_PORT_WiFi,
3330
);
34-
console.info("Found printers:", printers);
31+
console.info("Found printers:", results);
3532

36-
await connect(printers[0].ipAddress);
37-
await printText("Hello World!\n");
38-
await cutPaper(ESCPOSConst.CMP_CUT_FULL_PREFEED);
39-
await disconnect();
33+
const printer = await connect(results[0].ipAddress);
34+
await printer.printText("Hello World!\n");
35+
await printer.cutPaper(ESCPOSConst.CMP_CUT_FULL_PREFEED);
36+
await printer.disconnect();
4037
};
4138
```
4239

examples/testprint-app/app/(tabs)/index.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,79 +11,72 @@ import {
1111
} from "react-native";
1212
import {
1313
connect,
14-
cutPaper,
15-
disconnect,
1614
ESCPOSConst,
17-
printerCheck,
18-
printQRCode,
19-
printText,
2015
searchCitizenPrinter,
21-
setEncoding,
22-
status,
2316
type CitizenPrinerInfo,
2417
type CitizenPrinerWiFiInfo,
2518
} from "react-native-citizen-escposprinter";
2619

2720
const testPrint = async (connectType: number, address?: string) => {
28-
await connect(connectType, address);
21+
const printer = await connect(connectType, address);
2922
console.log("✅ connected:", address);
30-
await printerCheck();
23+
await printer.printerCheck();
3124
console.log("✅ printerCheck");
32-
const printerStatus = await status();
33-
await setEncoding("UTF-8");
25+
const printerStatus = await printer.status();
26+
await printer.setEncoding("UTF-8");
3427
console.log("✅ status", printerStatus);
35-
await printText("Hello World!你好世界!\n");
36-
await printText(
28+
await printer.printText("Hello World!你好世界!\n");
29+
await printer.printText(
3730
"Hello World!你好世界!\n",
3831
ESCPOSConst.CMP_ALIGNMENT_LEFT,
3932
ESCPOSConst.CMP_FNT_DEFAULT,
4033
ESCPOSConst.CMP_TXT_2WIDTH | ESCPOSConst.CMP_TXT_2HEIGHT,
4134
);
42-
await printText(
35+
await printer.printText(
4336
"Hello World!你好世界!\n",
4437
ESCPOSConst.CMP_ALIGNMENT_LEFT,
4538
ESCPOSConst.CMP_FNT_DEFAULT,
4639
ESCPOSConst.CMP_TXT_3WIDTH | ESCPOSConst.CMP_TXT_3HEIGHT,
4740
);
48-
await printText(
41+
await printer.printText(
4942
"Hello World!你好世界!\n",
5043
ESCPOSConst.CMP_ALIGNMENT_LEFT,
5144
ESCPOSConst.CMP_FNT_DEFAULT,
5245
ESCPOSConst.CMP_TXT_4WIDTH | ESCPOSConst.CMP_TXT_4HEIGHT,
5346
);
54-
await printText(
47+
await printer.printText(
5548
"Hello World!你好世界!\n",
5649
ESCPOSConst.CMP_ALIGNMENT_LEFT,
5750
ESCPOSConst.CMP_FNT_DEFAULT,
5851
ESCPOSConst.CMP_TXT_5WIDTH | ESCPOSConst.CMP_TXT_5HEIGHT,
5952
);
60-
await printText(
53+
await printer.printText(
6154
"Hello World!你好世界!\n",
6255
ESCPOSConst.CMP_ALIGNMENT_LEFT,
6356
ESCPOSConst.CMP_FNT_DEFAULT,
6457
ESCPOSConst.CMP_TXT_6WIDTH | ESCPOSConst.CMP_TXT_6HEIGHT,
6558
);
66-
await printText(
59+
await printer.printText(
6760
"Hello World!你好世界!\n",
6861
ESCPOSConst.CMP_ALIGNMENT_LEFT,
6962
ESCPOSConst.CMP_FNT_DEFAULT,
7063
ESCPOSConst.CMP_TXT_7WIDTH | ESCPOSConst.CMP_TXT_7HEIGHT,
7164
);
72-
await printText(
65+
await printer.printText(
7366
"Hello World!你好世界!\n",
7467
ESCPOSConst.CMP_ALIGNMENT_LEFT,
7568
ESCPOSConst.CMP_FNT_DEFAULT,
7669
ESCPOSConst.CMP_TXT_8WIDTH | ESCPOSConst.CMP_TXT_8HEIGHT,
7770
);
78-
await printQRCode(
71+
await printer.printQRCode(
7972
"https://www.google.com",
8073
8,
8174
ESCPOSConst.CMP_QRCODE_EC_LEVEL_H,
8275
);
8376
console.log("✅ printText");
84-
await cutPaper(ESCPOSConst.CMP_CUT_FULL_PREFEED);
77+
await printer.cutPaper(ESCPOSConst.CMP_CUT_FULL_PREFEED);
8578
console.log("✅ cutPaper");
86-
await disconnect();
79+
await printer.disconnect();
8780
console.log("✅ disconnect");
8881
};
8982

0 commit comments

Comments
 (0)