@rdlabo/capacitor-brotherprint 6.2.0 → 6.4.0
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 +88 -38
- package/android/src/main/AndroidManifest.xml +2 -17
- package/android/src/main/java/jp/rdlabo/capacitor/plugin/brotherprint/BrotherPrint.kt +181 -88
- package/android/src/main/java/jp/rdlabo/capacitor/plugin/brotherprint/models/BrotherPrintSettings.kt +72 -28
- package/dist/docs.json +205 -75
- package/dist/esm/brother-printer.enum.d.ts +44 -25
- package/dist/esm/brother-printer.enum.js +46 -25
- package/dist/esm/brother-printer.enum.js.map +1 -1
- package/dist/esm/definitions.d.ts +66 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +46 -25
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +46 -25
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Model/PrintErrorModel.swift +19 -0
- package/ios/Plugin/Model/PrinterModel.swift +86 -30
- package/ios/Plugin/Model/PrinterSettingsModel.swift +54 -19
- package/ios/Plugin/Plugin.swift +61 -28
- package/ios/Plugin.xcworkspace/xcuserdata/sakakibara.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Capacitor Brother Print is a native Brother Print SDK implementation for iOS & Android. Support These models.
|
|
4
4
|
|
|
5
|
+
**This plugin is still in the RC (release candidate) phase.**
|
|
6
|
+
|
|
5
7
|
## Supported models
|
|
6
8
|
|
|
7
9
|
Each product link is an Amazon affiliate link. If you choose to make a purchase through these links, it would be greatly appreciated and **would help** support development costs. Thank you!
|
|
@@ -12,7 +14,7 @@ Each product link is an Amazon affiliate link. If you choose to make a purchase
|
|
|
12
14
|
| [QL-820NWB](https://amzn.to/3BXQ1aj) | QL_820NWB | ◯ | ※1 | ✗ | △ | ◯ | △ | ✗ |
|
|
13
15
|
| [QL-820NWBc](https://amzn.to/4fjhUIe) | QL_820NWB | ◯ | ※2 | ✗ | ✗ | ◯ | ◯ | ✗ |
|
|
14
16
|
| [TD-2320D](https://amzn.to/48EFCN3) | TD_2320D_203 | ✗ | ✗ | ✗ | △ | ✗ | ✗ | ✗ |
|
|
15
|
-
| [TD-2350D](https://amzn.to/48ma6TK) |
|
|
17
|
+
| [TD-2350D](https://amzn.to/48ma6TK) | TD_2350D_300 | ◯ | △ | △ | ◯ | ◯ | ◯ | △ |
|
|
16
18
|
|
|
17
19
|
Amazon Affiliate Links: **https://amzn.to/3AiiOFT**
|
|
18
20
|
|
|
@@ -22,17 +24,19 @@ Amazon Affiliate Links: **https://amzn.to/3AiiOFT**
|
|
|
22
24
|
| --- | -------------------------- |
|
|
23
25
|
| ◯ | Supported and tested |
|
|
24
26
|
| △ | Implemented but not tested |
|
|
25
|
-
|
|
|
27
|
+
| - | Plugin is not supported |
|
|
28
|
+
| ✗ | Device is not supported |
|
|
26
29
|
| BT | Bluetooth |
|
|
27
30
|
| BLE | Bluetooth Low Energy |
|
|
28
31
|
|
|
29
32
|
※1 Due to low Bluetooth version, connection is not possible with iOS. Ref: https://okbizcs.okwave.jp/brother/qa/q9932082.html
|
|
33
|
+
|
|
30
34
|
※2 The iOS/BT implementation for the QL-820NWBc is in place, but it’s uncertain if it functions correctly. It’s unclear whether this is an implementation issue, as Brother’s official app also doesn’t work well.
|
|
31
35
|
|
|
32
36
|
## How to install
|
|
33
37
|
|
|
34
38
|
```
|
|
35
|
-
% npm install @rdlabo/capacitor-brotherprint
|
|
39
|
+
% npm install @rdlabo/capacitor-brotherprint
|
|
36
40
|
```
|
|
37
41
|
|
|
38
42
|
## Initialize the Brother SDK
|
|
@@ -297,6 +301,8 @@ Basically, it times out, so there is no need to use it. Use it when you want to
|
|
|
297
301
|
addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc: (printers: BRLMChannelResult) => void) => Promise<PluginListenerHandle>
|
|
298
302
|
```
|
|
299
303
|
|
|
304
|
+
Find the printer that can connected to the device.
|
|
305
|
+
|
|
300
306
|
| Param | Type |
|
|
301
307
|
| ------------------ | -------------------------------------------------------------------------------------------- |
|
|
302
308
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrinterAvailable</a></code> |
|
|
@@ -313,6 +319,8 @@ addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc:
|
|
|
313
319
|
addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
314
320
|
```
|
|
315
321
|
|
|
322
|
+
Success Print Event
|
|
323
|
+
|
|
316
324
|
| Param | Type |
|
|
317
325
|
| ------------------ | --------------------------------------------------------------------------------- |
|
|
318
326
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrint</a></code> |
|
|
@@ -329,6 +337,9 @@ addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void)
|
|
|
329
337
|
addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
|
|
330
338
|
```
|
|
331
339
|
|
|
340
|
+
Failed to connect to the printer.
|
|
341
|
+
ex: Bluetooth is off, Printer is off, etc.
|
|
342
|
+
|
|
332
343
|
| Param | Type |
|
|
333
344
|
| ------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
334
345
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrintFailedCommunication</a></code> |
|
|
@@ -345,6 +356,8 @@ addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listen
|
|
|
345
356
|
addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
|
|
346
357
|
```
|
|
347
358
|
|
|
359
|
+
Failed to print.
|
|
360
|
+
|
|
348
361
|
| Param | Type |
|
|
349
362
|
| ------------------ | -------------------------------------------------------------------------------------- |
|
|
350
363
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrintError</a></code> |
|
|
@@ -370,7 +383,7 @@ addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info:
|
|
|
370
383
|
|
|
371
384
|
#### BRLMPrintOptions
|
|
372
385
|
|
|
373
|
-
<code>{ encodedImage: string; /** * Should use enum <a href="#
|
|
386
|
+
<code>{ encodedImage: string; /** * Should use enum <a href="#brlmprintermodelname">BRLMPrinterModelName</a> */ modelName: <a href="#brlmprintermodelname">BRLMPrinterModelName</a>; } & <a href="#partial">Partial</a><<a href="#brlmchannelresult">BRLMChannelResult</a>> & (<a href="#brlmprinterqlmodelsettings">BRLMPrinterQLModelSettings</a> | <a href="#brlmprintertdmodelsettings">BRLMPrinterTDModelSettings</a>)</code>
|
|
374
387
|
|
|
375
388
|
|
|
376
389
|
#### Partial
|
|
@@ -382,14 +395,19 @@ Make all properties in T optional
|
|
|
382
395
|
|
|
383
396
|
#### BRLMChannelResult
|
|
384
397
|
|
|
385
|
-
<code>{ port: 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string;
|
|
398
|
+
<code>{ port: 'usb' | 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string; /** * This need to connect to the printer. * wifi: IP Address * bluetooth: macAddress * bluetoothLowEnergy: modelName for bluetoothLowEnergy */ channelInfo: string; }</code>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
#### BRLMPrinterQLModelSettings
|
|
402
|
+
|
|
403
|
+
<code>{ /** * Should use enum <a href="#brlmprinterlabelname">BRLMPrinterLabelName</a> */ labelName: <a href="#brlmprinterlabelname">BRLMPrinterLabelName</a>; } & <a href="#brlmprintersettings">BRLMPrinterSettings</a></code>
|
|
386
404
|
|
|
387
405
|
|
|
388
406
|
#### BRLMPrinterSettings
|
|
389
407
|
|
|
390
408
|
These are optional. If these are not set, default values are assigned by the printer.
|
|
391
409
|
|
|
392
|
-
<code>{ /** * The number of copies you print. */ numberOfCopies?: <a href="#brlmprinternumberofcopies">BRLMPrinterNumberOfCopies</a>; /** * Whether the auto-cut is enabled or not. If true, your printer cut the paper each page. */ autoCut?: <a href="#brlmprinterautocuttype">BRLMPrinterAutoCutType</a>; /** * A scale mode that specifies how your data is scaled in a print area of your printer. */ scaleMode?: <a href="#brlmprinterscalemode">BRLMPrinterScaleMode</a>; /** * A scale value. This is effective when ScaleMode is ScaleValue. */ scaleValue?: <a href="#brlmprinterscalevaluetype">BRLMPrinterScaleValueType</a>; /** * A way to rasterize your data. */ halftone?: <a href="#brlmprinterhalftone">BRLMPrinterHalftone</a>; /** * A threshold value. This is effective when the Halftone is Threshold. */ halftoneThreshold?: <a href="#brlmprinterhalftonethresholdtype">BRLMPrinterHalftoneThresholdType</a>; /** * An image rotation that specifies the angle in which your data is placed in the print area. Rotation direction is clockwise. */ imageRotation?: <a href="#brlmprinterimagerotation">BRLMPrinterImageRotation</a>; /** * A vertical alignment that specifies how your data is placed in the printable area. */ verticalAlignment?: <a href="#brlmprinterverticalalignment">BRLMPrinterVerticalAlignment</a>; /** * A horizontal alignment that specifies how your data is placed in the printable area. */ horizontalAlignment?: <a href="#brlmprinterhorizontalalignment">BRLMPrinterHorizontalAlignment</a>; /** * A compress mode that specifies how to compress your data. * note: This is ios only. */ compressMode?: <a href="#brlmprintercompressmode">BRLMPrinterCompressMode</a>; /** * A priority that is print speed or print quality. Whether or not this has an effect is depend on your printer. */ printQuality?: <a href="#brlmprinterprintquality">BRLMPrinterPrintQuality</a>;
|
|
410
|
+
<code>{ /** * The number of copies you print. */ numberOfCopies?: <a href="#brlmprinternumberofcopies">BRLMPrinterNumberOfCopies</a>; /** * Whether the auto-cut is enabled or not. If true, your printer cut the paper each page. */ autoCut?: <a href="#brlmprinterautocuttype">BRLMPrinterAutoCutType</a>; /** * A scale mode that specifies how your data is scaled in a print area of your printer. */ scaleMode?: <a href="#brlmprinterscalemode">BRLMPrinterScaleMode</a>; /** * A scale value. This is effective when ScaleMode is ScaleValue. */ scaleValue?: <a href="#brlmprinterscalevaluetype">BRLMPrinterScaleValueType</a>; /** * A way to rasterize your data. */ halftone?: <a href="#brlmprinterhalftone">BRLMPrinterHalftone</a>; /** * A threshold value. This is effective when the Halftone is Threshold. */ halftoneThreshold?: <a href="#brlmprinterhalftonethresholdtype">BRLMPrinterHalftoneThresholdType</a>; /** * An image rotation that specifies the angle in which your data is placed in the print area. Rotation direction is clockwise. */ imageRotation?: <a href="#brlmprinterimagerotation">BRLMPrinterImageRotation</a>; /** * A vertical alignment that specifies how your data is placed in the printable area. */ verticalAlignment?: <a href="#brlmprinterverticalalignment">BRLMPrinterVerticalAlignment</a>; /** * A horizontal alignment that specifies how your data is placed in the printable area. */ horizontalAlignment?: <a href="#brlmprinterhorizontalalignment">BRLMPrinterHorizontalAlignment</a>; /** * A compress mode that specifies how to compress your data. * note: This is ios only. */ compressMode?: <a href="#brlmprintercompressmode">BRLMPrinterCompressMode</a>; /** * A priority that is print speed or print quality. Whether or not this has an effect is depend on your printer. */ printQuality?: <a href="#brlmprinterprintquality">BRLMPrinterPrintQuality</a>; }</code>
|
|
393
411
|
|
|
394
412
|
|
|
395
413
|
#### BRLMPrinterNumberOfCopies
|
|
@@ -412,9 +430,14 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
412
430
|
<code>number</code>
|
|
413
431
|
|
|
414
432
|
|
|
433
|
+
#### BRLMPrinterTDModelSettings
|
|
434
|
+
|
|
435
|
+
<code>{ /** * Should use enum <a href="#brkmprintercustompapertype">BRKMPrinterCustomPaperType</a> */ paperType: <a href="#brkmprintercustompapertype">BRKMPrinterCustomPaperType</a>; /** * The width of the label. For example, the RD-U04J1 is 60.0 wide. */ tapeWidth: number; /** * The length of the label. For example, the RD-U04J1 is 60.0 wide. */ tapeLength: number; /** * It is the difference between a sticker and a mount. * For example, the RD-U04J1 is `1.0, 2.0, 1.0, 2.0` */ marginTop: number; marginRight: number; marginBottom: number; marginLeft: number; /** * The spacing between seals. For example, the RD-U04J1 is 0.2. */ gapLength: number; paperMarkPosition: number; paperMarkLength: number; /** * Should use enum <a href="#brkmprintercustompaperunit">BRKMPrinterCustomPaperUnit</a>. * For example, the RD-U04J1 is mm. */ paperUnit: <a href="#brkmprintercustompaperunit">BRKMPrinterCustomPaperUnit</a>; }</code>
|
|
436
|
+
|
|
437
|
+
|
|
415
438
|
#### BRLMSearchOption
|
|
416
439
|
|
|
417
|
-
<code>{ port: 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; /** * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }</code>
|
|
440
|
+
<code>{ /** * 'usb' is android only, and now developing. */ port: 'usb' | 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; /** * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }</code>
|
|
418
441
|
|
|
419
442
|
|
|
420
443
|
#### ErrorInfo
|
|
@@ -425,45 +448,55 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
425
448
|
### Enums
|
|
426
449
|
|
|
427
450
|
|
|
428
|
-
#### BRLMPrinterLabelName
|
|
429
|
-
|
|
430
|
-
| Members | Value |
|
|
431
|
-
| ------------- | ---------------------- |
|
|
432
|
-
| **`W17H54`** | <code>'W17H54'</code> |
|
|
433
|
-
| **`W17H87`** | <code>'W17H87'</code> |
|
|
434
|
-
| **`W23H23`** | <code>'W23H23'</code> |
|
|
435
|
-
| **`W29H42`** | <code>'W29H42'</code> |
|
|
436
|
-
| **`W29H90`** | <code>'W29H90'</code> |
|
|
437
|
-
| **`W38H90`** | <code>'W38H90'</code> |
|
|
438
|
-
| **`W39H48`** | <code>'W39H48'</code> |
|
|
439
|
-
| **`W52H29`** | <code>'W52H29'</code> |
|
|
440
|
-
| **`W62H29`** | <code>'W62H29'</code> |
|
|
441
|
-
| **`W62H100`** | <code>'W62H100'</code> |
|
|
442
|
-
| **`W12`** | <code>'W12'</code> |
|
|
443
|
-
| **`W29`** | <code>'W29'</code> |
|
|
444
|
-
| **`W38`** | <code>'W38'</code> |
|
|
445
|
-
| **`W50`** | <code>'W50'</code> |
|
|
446
|
-
| **`W54`** | <code>'W54'</code> |
|
|
447
|
-
| **`W62`** | <code>'W62'</code> |
|
|
448
|
-
| **`W60H86`** | <code>'W60H86'</code> |
|
|
449
|
-
| **`W62RB`** | <code>'W62RB'</code> |
|
|
450
|
-
| **`W54H29`** | <code>'W54H29'</code> |
|
|
451
|
-
| **`W12DIA`** | <code>'W12DIA'</code> |
|
|
452
|
-
| **`W24DIA`** | <code>'W24DIA'</code> |
|
|
453
|
-
| **`W58DIA`** | <code>'W58DIA'</code> |
|
|
454
|
-
| **`W62H60`** | <code>'W62H60'</code> |
|
|
455
|
-
| **`W62H75`** | <code>'W62H75'</code> |
|
|
456
|
-
|
|
457
|
-
|
|
458
451
|
#### BRLMPrinterModelName
|
|
459
452
|
|
|
460
453
|
| Members | Value |
|
|
461
454
|
| ------------------ | --------------------------- |
|
|
455
|
+
| **`QL_800`** | <code>'QL_800'</code> |
|
|
462
456
|
| **`QL_810W`** | <code>'QL_810W'</code> |
|
|
463
457
|
| **`QL_820NWB`** | <code>'QL_820NWB'</code> |
|
|
464
458
|
| **`TD_2320D_203`** | <code>'TD_2320D_203'</code> |
|
|
465
459
|
| **`TD_2030AD`** | <code>'TD_2030AD'</code> |
|
|
466
|
-
| **`
|
|
460
|
+
| **`TD_2350D_300`** | <code>'TD_2350D_300'</code> |
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
#### BRLMPrinterLabelName
|
|
464
|
+
|
|
465
|
+
| Members | Value |
|
|
466
|
+
| -------------------- | ----------------------------- |
|
|
467
|
+
| **`DieCutW17H54`** | <code>'DieCutW17H54'</code> |
|
|
468
|
+
| **`DieCutW17H87`** | <code>'DieCutW17H87'</code> |
|
|
469
|
+
| **`DieCutW23H23`** | <code>'DieCutW23H23'</code> |
|
|
470
|
+
| **`DieCutW29H42`** | <code>'DieCutW29H42'</code> |
|
|
471
|
+
| **`DieCutW29H90`** | <code>'DieCutW29H90'</code> |
|
|
472
|
+
| **`DieCutW38H90`** | <code>'DieCutW38H90'</code> |
|
|
473
|
+
| **`DieCutW39H48`** | <code>'DieCutW39H48'</code> |
|
|
474
|
+
| **`DieCutW52H29`** | <code>'DieCutW52H29'</code> |
|
|
475
|
+
| **`DieCutW62H29`** | <code>'DieCutW62H29'</code> |
|
|
476
|
+
| **`DieCutW62H60`** | <code>'DieCutW62H60'</code> |
|
|
477
|
+
| **`DieCutW62H75`** | <code>'DieCutW62H75'</code> |
|
|
478
|
+
| **`DieCutW62H100`** | <code>'DieCutW62H100'</code> |
|
|
479
|
+
| **`DieCutW60H86`** | <code>'DieCutW60H86'</code> |
|
|
480
|
+
| **`DieCutW54H29`** | <code>'DieCutW54H29'</code> |
|
|
481
|
+
| **`DieCutW102H51`** | <code>'DieCutW102H51'</code> |
|
|
482
|
+
| **`DieCutW102H152`** | <code>'DieCutW102H152'</code> |
|
|
483
|
+
| **`DieCutW103H164`** | <code>'DieCutW103H164'</code> |
|
|
484
|
+
| **`RollW12`** | <code>'RollW12'</code> |
|
|
485
|
+
| **`RollW29`** | <code>'RollW29'</code> |
|
|
486
|
+
| **`RollW38`** | <code>'RollW38'</code> |
|
|
487
|
+
| **`RollW50`** | <code>'RollW50'</code> |
|
|
488
|
+
| **`RollW54`** | <code>'RollW54'</code> |
|
|
489
|
+
| **`RollW62`** | <code>'RollW62'</code> |
|
|
490
|
+
| **`RollW62RB`** | <code>'RollW62RB'</code> |
|
|
491
|
+
| **`RollW102`** | <code>'RollW102'</code> |
|
|
492
|
+
| **`RollW103`** | <code>'RollW103'</code> |
|
|
493
|
+
| **`DTRollW90`** | <code>'DTRollW90'</code> |
|
|
494
|
+
| **`DTRollW102`** | <code>'DTRollW102'</code> |
|
|
495
|
+
| **`DTRollW102H51`** | <code>'DTRollW102H51'</code> |
|
|
496
|
+
| **`DTRollW102H152`** | <code>'DTRollW102H152'</code> |
|
|
497
|
+
| **`RoundW12DIA`** | <code>'RoundW12DIA'</code> |
|
|
498
|
+
| **`RoundW24DIA`** | <code>'RoundW24DIA'</code> |
|
|
499
|
+
| **`RoundW58DIA`** | <code>'RoundW58DIA'</code> |
|
|
467
500
|
|
|
468
501
|
|
|
469
502
|
#### BRLMPrinterScaleMode
|
|
@@ -530,6 +563,23 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
530
563
|
| **`Fast`** | <code>'Fast'</code> |
|
|
531
564
|
|
|
532
565
|
|
|
566
|
+
#### BRKMPrinterCustomPaperType
|
|
567
|
+
|
|
568
|
+
| Members | Value |
|
|
569
|
+
| ------------------- | ---------------------------- |
|
|
570
|
+
| **`rollPaper`** | <code>'rollPaper'</code> |
|
|
571
|
+
| **`dieCutPaper`** | <code>'dieCutPaper'</code> |
|
|
572
|
+
| **`markRollPaper`** | <code>'markRollPaper'</code> |
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
#### BRKMPrinterCustomPaperUnit
|
|
576
|
+
|
|
577
|
+
| Members | Value |
|
|
578
|
+
| ---------- | ------------------- |
|
|
579
|
+
| **`mm`** | <code>'mm'</code> |
|
|
580
|
+
| **`inch`** | <code>'inch'</code> |
|
|
581
|
+
|
|
582
|
+
|
|
533
583
|
#### BrotherPrintEventsEnum
|
|
534
584
|
|
|
535
585
|
| Members | Value |
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
6
|
-
|
|
7
|
-
<!-- For Wi-Fi -->
|
|
8
|
-
<uses-permission android:name="android.permission.INTERNET" />
|
|
9
|
-
|
|
10
|
-
<!-- For Bluetooth -->
|
|
11
|
-
<uses-permission android:name="android.permission.BLUETOOTH" />
|
|
12
|
-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
|
13
|
-
|
|
14
|
-
<!-- For Bluetooth Low Energy -->
|
|
15
|
-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
16
|
-
</manifest>
|
|
17
|
-
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
package jp.rdlabo.capacitor.plugin.brotherprint
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.app.PendingIntent
|
|
5
|
+
import android.bluetooth.BluetoothAdapter
|
|
3
6
|
import android.bluetooth.BluetoothManager
|
|
7
|
+
import android.content.BroadcastReceiver
|
|
4
8
|
import android.content.Context
|
|
9
|
+
import android.content.Intent
|
|
10
|
+
import android.content.IntentFilter
|
|
5
11
|
import android.graphics.BitmapFactory
|
|
12
|
+
import android.hardware.usb.UsbDevice
|
|
13
|
+
import android.hardware.usb.UsbManager
|
|
14
|
+
import android.os.Build
|
|
6
15
|
import android.util.Base64
|
|
7
16
|
import android.util.Log
|
|
8
|
-
import com.brother.ptouch.sdk.LabelInfo
|
|
9
|
-
import com.brother.ptouch.sdk.Printer
|
|
10
|
-
import com.brother.ptouch.sdk.PrinterInfo
|
|
11
17
|
import com.brother.sdk.lmprinter.BLESearchOption
|
|
12
18
|
import com.brother.sdk.lmprinter.Channel
|
|
13
19
|
import com.brother.sdk.lmprinter.NetworkSearchOption
|
|
20
|
+
import com.brother.sdk.lmprinter.OpenChannelError
|
|
21
|
+
import com.brother.sdk.lmprinter.PrintError
|
|
22
|
+
import com.brother.sdk.lmprinter.PrinterDriverGenerator
|
|
23
|
+
import com.brother.sdk.lmprinter.PrinterModel
|
|
14
24
|
import com.brother.sdk.lmprinter.PrinterSearcher
|
|
15
25
|
import com.brother.sdk.lmprinter.PrinterSearcher.cancelNetworkSearch
|
|
26
|
+
import com.brother.sdk.lmprinter.setting.PrintSettings
|
|
27
|
+
import com.brother.sdk.lmprinter.setting.QLPrintSettings
|
|
28
|
+
import com.brother.sdk.lmprinter.setting.TDPrintSettings
|
|
16
29
|
import com.getcapacitor.JSObject
|
|
17
|
-
import com.getcapacitor.Plugin
|
|
18
|
-
import android.Manifest;
|
|
19
30
|
import com.getcapacitor.PermissionState
|
|
31
|
+
import com.getcapacitor.Plugin
|
|
20
32
|
import com.getcapacitor.PluginCall
|
|
21
33
|
import com.getcapacitor.PluginMethod
|
|
22
34
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
@@ -25,6 +37,7 @@ import com.getcapacitor.annotation.PermissionCallback
|
|
|
25
37
|
import jp.rdlabo.capacitor.plugin.brotherprint.models.BrotherPrintEvent
|
|
26
38
|
import jp.rdlabo.capacitor.plugin.brotherprint.models.BrotherPrintSettings
|
|
27
39
|
|
|
40
|
+
|
|
28
41
|
@CapacitorPlugin(
|
|
29
42
|
name = "BrotherPrint",
|
|
30
43
|
permissions = [
|
|
@@ -49,9 +62,13 @@ import jp.rdlabo.capacitor.plugin.brotherprint.models.BrotherPrintSettings
|
|
|
49
62
|
class BrotherPrint : Plugin() {
|
|
50
63
|
private var cancelRoutineWiFi: (() -> Unit)? = null
|
|
51
64
|
private var cancelRoutineBluetooth: (() -> Unit)? = null
|
|
65
|
+
|
|
66
|
+
private val ActionUSBPermission = "jp.rdlabo.capacitor.plugin.brotherprint.USB_PERMISSION"
|
|
52
67
|
private val PERMISSION_DENIED_ERROR =
|
|
53
68
|
"Unable to do call operation, user denied permission request"
|
|
54
69
|
|
|
70
|
+
private var storeCall: PluginCall? = null
|
|
71
|
+
|
|
55
72
|
@PluginMethod
|
|
56
73
|
fun printImage(call: PluginCall) {
|
|
57
74
|
val encodedImage = call.getString("encodedImage", "")
|
|
@@ -64,96 +81,86 @@ class BrotherPrint : Plugin() {
|
|
|
64
81
|
val decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
|
|
65
82
|
|
|
66
83
|
val port: String? = call.getString("port", "wifi")
|
|
67
|
-
val
|
|
68
|
-
val
|
|
69
|
-
val serialNumber: String? = call.getString("serialNumber", "")
|
|
70
|
-
val macAddress: String? = call.getString("macAddress", "")
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
val
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
settings
|
|
82
|
-
|
|
83
|
-
settings.
|
|
84
|
-
} else if (port == "bluetooth") {
|
|
85
|
-
val manager =
|
|
86
|
-
bridge.context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
87
|
-
printer.setBluetooth(manager.adapter)
|
|
88
|
-
settings.port = PrinterInfo.Port.BLUETOOTH
|
|
89
|
-
settings.macAddress = serialNumber
|
|
84
|
+
val channelInfo: String? = call.getString("channelInfo", "")
|
|
85
|
+
// val localName: String? = call.getString("localName", "")
|
|
86
|
+
// val serialNumber: String? = call.getString("serialNumber", "")
|
|
87
|
+
// val macAddress: String? = call.getString("macAddress", "")
|
|
88
|
+
|
|
89
|
+
lateinit var settings: PrintSettings;
|
|
90
|
+
val modelName = call.getString("modelName", "QL_820NWB")!!
|
|
91
|
+
val printerModel = PrinterModel.entries.find { it.name == modelName }
|
|
92
|
+
|
|
93
|
+
if (printerModel != null && modelName.startsWith("QL")) {
|
|
94
|
+
settings = QLPrintSettings(printerModel);
|
|
95
|
+
settings = BrotherPrintSettings().modelQLSettings(call, settings)
|
|
96
|
+
settings.workPath = bridge.context.cacheDir.path;
|
|
97
|
+
} else if (printerModel != null && modelName.startsWith("TD")) {
|
|
98
|
+
settings = TDPrintSettings(printerModel)
|
|
99
|
+
settings = BrotherPrintSettings().modelTDSettings(call, settings)
|
|
100
|
+
settings.workPath = bridge.context.cacheDir.path;
|
|
90
101
|
} else {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
printer.setBluetooth(manager.adapter)
|
|
94
|
-
settings.port = PrinterInfo.Port.BLE
|
|
102
|
+
call.reject("Error - modelName:$modelName is not supported")
|
|
103
|
+
return;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
Thread {
|
|
107
|
+
val channel: Channel = when (port) {
|
|
108
|
+
"usb" -> Channel.newUsbChannel(bridge.context.getSystemService(Context.USB_SERVICE) as UsbManager)
|
|
109
|
+
"wifi" -> Channel.newWifiChannel(channelInfo)
|
|
110
|
+
"bluetooth" -> Channel.newBluetoothChannel(channelInfo, getBluetoothAdapter(bridge.context))
|
|
111
|
+
"bluetoothLowEnergy" -> Channel.newBluetoothLowEnergyChannel(
|
|
112
|
+
channelInfo, bridge.context, getBluetoothAdapter(bridge.context)
|
|
113
|
+
)
|
|
114
|
+
else -> {
|
|
115
|
+
call.reject("Error - port:$port is not supported")
|
|
116
|
+
return@Thread
|
|
117
|
+
}
|
|
118
|
+
}
|
|
101
119
|
|
|
102
|
-
|
|
120
|
+
val result = PrinterDriverGenerator.openChannel(channel)
|
|
121
|
+
if (result.error.code != OpenChannelError.ErrorCode.NoError) {
|
|
122
|
+
this.notifyListeners(BrotherPrintEvent.onPrintFailedCommunication.webEventName,
|
|
123
|
+
JSObject().put("code", result.error.code)
|
|
124
|
+
.put("message", result.error.code.toString())
|
|
125
|
+
)
|
|
126
|
+
call.reject("Error - openChannel: " + result.error.code.toString())
|
|
127
|
+
return@Thread
|
|
128
|
+
}
|
|
103
129
|
|
|
104
|
-
|
|
130
|
+
val printerDriver = result.driver
|
|
105
131
|
|
|
106
|
-
|
|
107
|
-
val setResult = Printer.getResult()
|
|
108
|
-
notifyListeners(
|
|
109
|
-
BrotherPrintEvent.onPrintError.webEventName,
|
|
110
|
-
JSObject().put("code", setResult.errorCode)
|
|
111
|
-
.put("message", setResult.toString())
|
|
112
|
-
)
|
|
113
|
-
}
|
|
132
|
+
val printError: PrintError = printerDriver.printImage(decodedByte, settings)
|
|
114
133
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.put("message", result.toString())
|
|
125
|
-
)
|
|
126
|
-
} else {
|
|
127
|
-
Log.d("TAG", "ERROR - " + result.errorCode)
|
|
128
|
-
notifyListeners(
|
|
129
|
-
BrotherPrintEvent.onPrintError.webEventName,
|
|
130
|
-
JSObject().put("code", result.errorCode)
|
|
131
|
-
.put("message", result.toString())
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
printer.endCommunication()
|
|
136
|
-
} else {
|
|
137
|
-
notifyListeners(
|
|
138
|
-
BrotherPrintEvent.onPrintFailedCommunication.webEventName,
|
|
139
|
-
JSObject().put("code", "0")
|
|
140
|
-
)
|
|
141
|
-
}
|
|
134
|
+
if (printError.code != PrintError.ErrorCode.NoError) {
|
|
135
|
+
printerDriver.closeChannel()
|
|
136
|
+
notifyListeners(
|
|
137
|
+
BrotherPrintEvent.onPrintError.webEventName,
|
|
138
|
+
JSObject().put("code", printError.code)
|
|
139
|
+
.put("message", result.error.code.toString())
|
|
140
|
+
)
|
|
141
|
+
call.reject("Error - Print Image: " + result.error.code.toString())
|
|
142
|
+
return@Thread
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
|
|
145
|
+
printerDriver.closeChannel()
|
|
146
|
+
|
|
146
147
|
notifyListeners(
|
|
147
|
-
BrotherPrintEvent.
|
|
148
|
-
|
|
148
|
+
BrotherPrintEvent.onPrint.webEventName,
|
|
149
|
+
JSObject()
|
|
149
150
|
)
|
|
150
|
-
call.
|
|
151
|
-
}
|
|
151
|
+
call.resolve()
|
|
152
|
+
}.start()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private fun getBluetoothAdapter(context: Context): BluetoothAdapter? {
|
|
156
|
+
val manager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
157
|
+
return manager.adapter
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
@PluginMethod
|
|
155
161
|
fun search(call: PluginCall) {
|
|
156
162
|
when(call.getString("port", "wifi")) {
|
|
163
|
+
"usb" -> this.searchUsbPrinter(call)
|
|
157
164
|
"wifi" -> this.searchWiFiPrinter(call)
|
|
158
165
|
"bluetooth" -> this.checkBLEChannel(call)
|
|
159
166
|
"bluetoothLowEnergy" -> this.searchBLEPrinter(call)
|
|
@@ -161,6 +168,41 @@ class BrotherPrint : Plugin() {
|
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
|
|
171
|
+
private fun searchUsbPrinter(call: PluginCall) {
|
|
172
|
+
if (!this.requestUsbPermission(call)) {
|
|
173
|
+
this.storeCall = call;
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
this.storeCall = null
|
|
177
|
+
|
|
178
|
+
Thread {
|
|
179
|
+
val result = PrinterSearcher.startUSBSearch(bridge.context)
|
|
180
|
+
|
|
181
|
+
when (result.error.code) {
|
|
182
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.NoError -> {
|
|
183
|
+
}
|
|
184
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.NotPermitted -> {
|
|
185
|
+
// TODO: has error
|
|
186
|
+
}
|
|
187
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.Canceled,
|
|
188
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.InterfaceInactive,
|
|
189
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.InterfaceUnsupported,
|
|
190
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.AlreadySearching,
|
|
191
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.UnknownError -> {
|
|
192
|
+
}
|
|
193
|
+
null -> {}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (channel in result.channels){
|
|
197
|
+
this.notifyListeners(
|
|
198
|
+
BrotherPrintEvent.onPrinterAvailable.webEventName,
|
|
199
|
+
this.chanelToPrinter("usb", channel)
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}.start()
|
|
203
|
+
call.resolve();
|
|
204
|
+
}
|
|
205
|
+
|
|
164
206
|
private fun searchWiFiPrinter(call: PluginCall) {
|
|
165
207
|
Log.d("brother", "searchWiFiPrinter")
|
|
166
208
|
Thread {
|
|
@@ -185,7 +227,7 @@ class BrotherPrint : Plugin() {
|
|
|
185
227
|
|
|
186
228
|
private fun checkBLEChannel(call: PluginCall) {
|
|
187
229
|
if (!isBluetoothPermissionGranted()) {
|
|
188
|
-
|
|
230
|
+
requestPermissionForAlias("bluetooth", call, "permissionCallback");
|
|
189
231
|
} else {
|
|
190
232
|
Log.d("brother", "checkBLEChannel")
|
|
191
233
|
Thread {
|
|
@@ -200,7 +242,10 @@ class BrotherPrint : Plugin() {
|
|
|
200
242
|
|
|
201
243
|
private fun searchBLEPrinter(call: PluginCall) {
|
|
202
244
|
if (!isBluetoothPermissionGranted()) {
|
|
203
|
-
|
|
245
|
+
requestPermissionForAlias("bluetooth", call, "permissionCallback");
|
|
246
|
+
return;
|
|
247
|
+
} else if (!isLocationPermissionGranted()) {
|
|
248
|
+
requestPermissionForAlias("location", call, "permissionCallback");
|
|
204
249
|
return;
|
|
205
250
|
} else {
|
|
206
251
|
Log.d("brother", "searchBLEPrinter")
|
|
@@ -226,12 +271,13 @@ class BrotherPrint : Plugin() {
|
|
|
226
271
|
}
|
|
227
272
|
|
|
228
273
|
private fun chanelToPrinter(port: String, channel: Channel): JSObject? {
|
|
274
|
+
Log.d("brother", channel.toString());
|
|
229
275
|
val modelName = channel.extraInfo[Channel.ExtraInfoKey.ModelName] ?: ""
|
|
230
276
|
val serialNumber = channel.extraInfo[Channel.ExtraInfoKey.SerialNubmer] ?: ""
|
|
231
277
|
val macAddress = channel.extraInfo[Channel.ExtraInfoKey.MACAddress] ?: ""
|
|
232
278
|
val nodeName = channel.extraInfo[Channel.ExtraInfoKey.NodeName] ?: ""
|
|
233
279
|
val location = channel.extraInfo[Channel.ExtraInfoKey.Location] ?: ""
|
|
234
|
-
val
|
|
280
|
+
val channelInfo = channel.channelInfo
|
|
235
281
|
|
|
236
282
|
return JSObject()
|
|
237
283
|
.put("port", port)
|
|
@@ -240,22 +286,24 @@ class BrotherPrint : Plugin() {
|
|
|
240
286
|
.put("macAddress", macAddress)
|
|
241
287
|
.put("nodeName", nodeName)
|
|
242
288
|
.put("location", location)
|
|
243
|
-
.put("
|
|
289
|
+
.put("channelInfo", channelInfo)
|
|
244
290
|
}
|
|
245
291
|
|
|
246
292
|
@PluginMethod
|
|
247
|
-
fun cancelSearchWiFiPrinter(call: PluginCall
|
|
293
|
+
fun cancelSearchWiFiPrinter(call: PluginCall) {
|
|
248
294
|
Thread {
|
|
249
295
|
this.cancelRoutineWiFi?.invoke()
|
|
250
296
|
this.cancelRoutineWiFi = null
|
|
297
|
+
call.resolve()
|
|
251
298
|
}.start()
|
|
252
299
|
}
|
|
253
300
|
|
|
254
301
|
@PluginMethod
|
|
255
|
-
fun cancelSearchBluetoothPrinter(call: PluginCall
|
|
302
|
+
fun cancelSearchBluetoothPrinter(call: PluginCall) {
|
|
256
303
|
Thread {
|
|
257
304
|
this.cancelRoutineBluetooth?.invoke()
|
|
258
305
|
this.cancelRoutineBluetooth = null
|
|
306
|
+
call.resolve()
|
|
259
307
|
}.start()
|
|
260
308
|
}
|
|
261
309
|
|
|
@@ -272,11 +320,56 @@ class BrotherPrint : Plugin() {
|
|
|
272
320
|
return
|
|
273
321
|
}
|
|
274
322
|
when (call.methodName) {
|
|
275
|
-
"
|
|
276
|
-
"searchBLEPrinter" -> searchBLEPrinter(call)
|
|
323
|
+
"search" -> this.search(call)
|
|
277
324
|
}
|
|
278
325
|
}
|
|
279
326
|
|
|
327
|
+
/**
|
|
328
|
+
* TODO: This is not called for in spite of registration.
|
|
329
|
+
* Therefore, it is now necessary for the user to run it again after permission is granted.
|
|
330
|
+
*/
|
|
331
|
+
private val usbReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
|
332
|
+
override fun onReceive(context: Context?, intent: Intent?) {
|
|
333
|
+
if (intent?.action == ActionUSBPermission && intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
|
334
|
+
storeCall?.let { searchUsbPrinter(it) }
|
|
335
|
+
} else {
|
|
336
|
+
storeCall?.reject("Error - usbReceiver can't current receiver");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private fun requestUsbPermission(call: PluginCall): Boolean {
|
|
342
|
+
val permissionIntent = PendingIntent.getBroadcast(
|
|
343
|
+
bridge.context, 0, Intent(ActionUSBPermission), PendingIntent.FLAG_IMMUTABLE
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
347
|
+
bridge.context.registerReceiver(
|
|
348
|
+
usbReceiver, IntentFilter(ActionUSBPermission),
|
|
349
|
+
Context.RECEIVER_NOT_EXPORTED
|
|
350
|
+
)
|
|
351
|
+
} else {
|
|
352
|
+
bridge.context.registerReceiver(
|
|
353
|
+
usbReceiver, IntentFilter(ActionUSBPermission)
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
var connectDevice: UsbDevice? = null
|
|
358
|
+
val usbManager = bridge.context.getSystemService(Context.USB_SERVICE) as UsbManager
|
|
359
|
+
for (device in usbManager.deviceList.values) {
|
|
360
|
+
connectDevice = device
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (connectDevice == null) {
|
|
364
|
+
call.reject("Error - connection failed: device not found")
|
|
365
|
+
return false
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
usbManager.requestPermission(connectDevice, permissionIntent)
|
|
369
|
+
|
|
370
|
+
return usbManager.hasPermission(connectDevice)
|
|
371
|
+
}
|
|
372
|
+
|
|
280
373
|
private fun isBluetoothPermissionGranted(): Boolean {
|
|
281
374
|
return getPermissionState("bluetooth") == PermissionState.GRANTED
|
|
282
375
|
}
|