@ancon/wildcat-utils 1.40.33 → 1.40.34
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 +1 @@
|
|
|
1
|
-
"use strict";const o=require("react"),k=require("dayjs"),
|
|
1
|
+
"use strict";const o=require("react"),k=require("dayjs"),R=require("@ancon/wildcat-printing"),j=require("../shared/hooks/usePrevious.js"),G=require("../shared/hooks/useMountedRef.js"),e=require("./types.js"),I=["TSP654"],V=1;function z(b,q,L,O,T=!1){const{useAppStore:N,useStarPrinterDiscover:_}=q,{selectedClientPrinterSelector:F}=L;function M(){const n=G(),v=N(),D=_(),f=o.useRef(void 0),[s,x]=o.useState(b),[a,l]=o.useState(),[S,P]=o.useState(),g=j(S),[A,p]=o.useState(),[U,w]=o.useState(O),r=o.useCallback(c=>{n!=null&&n.current&&x(c)},[n]),y=o.useCallback(async c=>{var i;(i=f.current)==null||i.stop(),r(e.StarCloudScanStatus.ScanningComplete);const u=String.fromCharCode(...c).trim();w(T?u.replace(/[\D]/gi,""):u)},[r]),h=o.useCallback(async({macAddress:c,ipAddress:u})=>{function i(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}const C={onStarted:t=>{if(t&&t.inputDevicesCount>0){const{inputDevicesCount:d}=t;r(e.StarCloudScanStatus.ReadyToScan),l({inputDeviceCount:d,lastConnectedOn:new Date})}},onStopped:t=>{t&&i(t),l(void 0)},inputDevice:{onConnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)+1;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t,lastConnectedOn:new Date})},onDisconnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)-1>=0?((a==null?void 0:a.inputDeviceCount)||0)-1:0;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t})},onCommunicationError:i,onDataReceived:t=>P({data:t,lastReceivedOn:new Date})}};if(f.current=R.monitor(u||c,C),n!=null&&n.current)try{await f.current.start()}catch(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}},[a,r,n]),m=o.useCallback(async()=>{n!=null&&n.current&&(r(e.StarCloudScanStatus.WaitingForPrinter),p(void 0),P(void 0),l(void 0),w(void 0));const c=F(v.getState()),{macAddress:u,serialNumber:i}=c;try{const t=(await D(2e3)).find(d=>u&&d.macAddress.toLowerCase()===u.toLowerCase()||i&&d.serialNumber===i);if(n!=null&&n.current){if(t){if(I.some(d=>{var E;return(E=t.model)==null?void 0:E.toLowerCase().includes(d.toLowerCase())})){r(e.StarCloudScanStatus.UnsupportedPrinter);return}h(t)}r(t?e.StarCloudScanStatus.PrinterDetected:e.StarCloudScanStatus.PrinterNotDetected)}}catch{n!=null&&n.current&&r(e.StarCloudScanStatus.PrinterNotDetected)}},[n,v,r,D,h]),W=s===e.StarCloudScanStatus.WaitingForPrinter||s===e.StarCloudScanStatus.PrinterDetected||s===e.StarCloudScanStatus.ReadyToScan||s===e.StarCloudScanStatus.ScanningComplete,H=s===e.StarCloudScanStatus.PrinterNotDetected||s===e.StarCloudScanStatus.ScanFailed||s===e.StarCloudScanStatus.CommunicationError||s===e.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!g&&(S==null?void 0:S.data)&&a&&(a!=null&&a.lastConnectedOn)){const{lastConnectedOn:u}=a,{lastReceivedOn:i,data:C}=S;k(i).diff(k(u),"second",!0)>V?y(C):P(void 0)}},[S,g,a,y]),o.useEffect(()=>(s===e.StarCloudScanStatus.WaitingForPrinter&&m(),()=>{var c;(c=f.current)==null||c.stop()}),[]),{startScan:m,changeDeviceStatus:r,scanStatus:s,reading:U,connectionError:A,isLoading:W,isError:H}}return M}module.exports=z;
|
|
@@ -1,118 +1,130 @@
|
|
|
1
|
-
import { useRef as V, useState as
|
|
2
|
-
import
|
|
1
|
+
import { useRef as V, useState as S, useCallback as p, useEffect as O } from "react";
|
|
2
|
+
import T from "dayjs";
|
|
3
3
|
import { monitor as q } from "@ancon/wildcat-printing";
|
|
4
4
|
import z from "../shared/hooks/usePrevious.mjs";
|
|
5
5
|
import B from "../shared/hooks/useMountedRef.mjs";
|
|
6
6
|
import { StarCloudScanStatus as e } from "./types.mjs";
|
|
7
7
|
const J = ["TSP654"], K = 1;
|
|
8
|
-
function tt(
|
|
8
|
+
function tt(N, k, F, M, b = !1) {
|
|
9
9
|
const { useAppStore: x, useStarPrinterDiscover: A } = k, { selectedClientPrinterSelector: U } = F;
|
|
10
10
|
function W() {
|
|
11
|
-
const
|
|
11
|
+
const n = B(), P = x(), D = A(), f = V(void 0), [i, H] = S(N), [o, C] = S(), [d, m] = S(), g = z(d), [R, v] = S(), [j, w] = S(M), r = p(
|
|
12
12
|
(c) => {
|
|
13
|
-
|
|
13
|
+
n != null && n.current && H(c);
|
|
14
14
|
},
|
|
15
|
-
[
|
|
16
|
-
), y =
|
|
15
|
+
[n]
|
|
16
|
+
), y = p(
|
|
17
17
|
async (c) => {
|
|
18
|
-
var
|
|
19
|
-
(
|
|
20
|
-
const
|
|
18
|
+
var s;
|
|
19
|
+
(s = f.current) == null || s.stop(), r(e.ScanningComplete);
|
|
20
|
+
const a = String.fromCharCode(...c).trim();
|
|
21
21
|
w(
|
|
22
|
-
b ?
|
|
22
|
+
b ? a.replace(/[\D]/gi, "") : a
|
|
23
23
|
);
|
|
24
24
|
},
|
|
25
|
-
[
|
|
26
|
-
), E =
|
|
27
|
-
async ({ macAddress: c, ipAddress:
|
|
28
|
-
function
|
|
29
|
-
|
|
25
|
+
[r]
|
|
26
|
+
), E = p(
|
|
27
|
+
async ({ macAddress: c, ipAddress: a }) => {
|
|
28
|
+
function s(t) {
|
|
29
|
+
r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const l = {
|
|
32
|
+
onStarted: (t) => {
|
|
33
|
+
if (t && t.inputDevicesCount > 0) {
|
|
34
|
+
const { inputDevicesCount: u } = t;
|
|
35
|
+
r(e.ReadyToScan), C({
|
|
36
|
+
inputDeviceCount: u,
|
|
37
|
+
lastConnectedOn: /* @__PURE__ */ new Date()
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onStopped: (t) => {
|
|
42
|
+
t && s(t), C(void 0);
|
|
43
|
+
},
|
|
32
44
|
inputDevice: {
|
|
33
45
|
onConnected: () => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
),
|
|
38
|
-
inputDeviceCount:
|
|
46
|
+
const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) + 1;
|
|
47
|
+
r(
|
|
48
|
+
t > 0 ? e.ReadyToScan : e.PrinterDetected
|
|
49
|
+
), C({
|
|
50
|
+
inputDeviceCount: t,
|
|
39
51
|
lastConnectedOn: /* @__PURE__ */ new Date()
|
|
40
52
|
});
|
|
41
53
|
},
|
|
42
54
|
onDisconnected: () => {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
),
|
|
47
|
-
inputDeviceCount:
|
|
55
|
+
const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 >= 0 ? ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 : 0;
|
|
56
|
+
r(
|
|
57
|
+
t > 0 ? e.ReadyToScan : e.PrinterDetected
|
|
58
|
+
), C({
|
|
59
|
+
inputDeviceCount: t
|
|
48
60
|
});
|
|
49
61
|
},
|
|
50
|
-
onCommunicationError:
|
|
51
|
-
onDataReceived: (
|
|
62
|
+
onCommunicationError: s,
|
|
63
|
+
onDataReceived: (t) => m({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
|
|
52
64
|
}
|
|
53
65
|
};
|
|
54
|
-
if (
|
|
66
|
+
if (f.current = q(a || c, l), n != null && n.current)
|
|
55
67
|
try {
|
|
56
|
-
await
|
|
57
|
-
} catch (
|
|
58
|
-
|
|
68
|
+
await f.current.start();
|
|
69
|
+
} catch (t) {
|
|
70
|
+
r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
|
|
59
71
|
}
|
|
60
72
|
},
|
|
61
|
-
[
|
|
62
|
-
), h =
|
|
63
|
-
|
|
64
|
-
const c = U(
|
|
73
|
+
[o, r, n]
|
|
74
|
+
), h = p(async () => {
|
|
75
|
+
n != null && n.current && (r(e.WaitingForPrinter), v(void 0), m(void 0), C(void 0), w(void 0));
|
|
76
|
+
const c = U(P.getState()), { macAddress: a, serialNumber: s } = c;
|
|
65
77
|
try {
|
|
66
|
-
const
|
|
67
|
-
(
|
|
78
|
+
const t = (await D(2e3)).find(
|
|
79
|
+
(u) => a && u.macAddress.toLowerCase() === a.toLowerCase() || s && u.serialNumber === s
|
|
68
80
|
);
|
|
69
|
-
if (
|
|
70
|
-
if (
|
|
81
|
+
if (n != null && n.current) {
|
|
82
|
+
if (t) {
|
|
71
83
|
if (J.some(
|
|
72
|
-
(
|
|
84
|
+
(u) => {
|
|
73
85
|
var L;
|
|
74
|
-
return (L =
|
|
86
|
+
return (L = t.model) == null ? void 0 : L.toLowerCase().includes(u.toLowerCase());
|
|
75
87
|
}
|
|
76
88
|
)) {
|
|
77
|
-
|
|
89
|
+
r(e.UnsupportedPrinter);
|
|
78
90
|
return;
|
|
79
91
|
}
|
|
80
|
-
E(
|
|
92
|
+
E(t);
|
|
81
93
|
}
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
r(
|
|
95
|
+
t ? e.PrinterDetected : e.PrinterNotDetected
|
|
84
96
|
);
|
|
85
97
|
}
|
|
86
98
|
} catch {
|
|
87
|
-
|
|
99
|
+
n != null && n.current && r(e.PrinterNotDetected);
|
|
88
100
|
}
|
|
89
101
|
}, [
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
n,
|
|
103
|
+
P,
|
|
104
|
+
r,
|
|
93
105
|
D,
|
|
94
106
|
E
|
|
95
|
-
]),
|
|
96
|
-
return
|
|
97
|
-
if (!g && (d == null ? void 0 : d.data) &&
|
|
98
|
-
const { lastConnectedOn:
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
]), G = i === e.WaitingForPrinter || i === e.PrinterDetected || i === e.ReadyToScan || i === e.ScanningComplete, I = i === e.PrinterNotDetected || i === e.ScanFailed || i === e.CommunicationError || i === e.UnsupportedPrinter;
|
|
108
|
+
return O(() => {
|
|
109
|
+
if (!g && (d == null ? void 0 : d.data) && o && (o != null && o.lastConnectedOn)) {
|
|
110
|
+
const { lastConnectedOn: a } = o, { lastReceivedOn: s, data: l } = d;
|
|
111
|
+
T(s).diff(
|
|
112
|
+
T(a),
|
|
101
113
|
"second",
|
|
102
114
|
!0
|
|
103
|
-
) > K ? y(
|
|
115
|
+
) > K ? y(l) : m(void 0);
|
|
104
116
|
}
|
|
105
|
-
}, [d, g,
|
|
117
|
+
}, [d, g, o, y]), O(() => (i === e.WaitingForPrinter && h(), () => {
|
|
106
118
|
var c;
|
|
107
|
-
(c =
|
|
119
|
+
(c = f.current) == null || c.stop();
|
|
108
120
|
}), []), {
|
|
109
121
|
startScan: h,
|
|
110
|
-
changeDeviceStatus:
|
|
122
|
+
changeDeviceStatus: r,
|
|
111
123
|
scanStatus: i,
|
|
112
|
-
reading:
|
|
113
|
-
connectionError:
|
|
114
|
-
isLoading:
|
|
115
|
-
isError:
|
|
124
|
+
reading: j,
|
|
125
|
+
connectionError: R,
|
|
126
|
+
isLoading: G,
|
|
127
|
+
isError: I
|
|
116
128
|
};
|
|
117
129
|
}
|
|
118
130
|
return W;
|