@ancon/wildcat-utils 1.54.0-check-optimizations.5 → 1.54.0-check-optimizations.6
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/index.js +1 -1
- package/index.mjs +396 -395
- package/package.json +6 -1
- package/printing/StarScanConnection.d.ts +64 -0
- package/printing/StarScanConnection.js +1 -0
- package/printing/StarScanConnection.mjs +93 -0
- package/printing/createStarCloudScanHook.d.ts +10 -0
- package/printing/createStarCloudScanHook.js +1 -1
- package/printing/createStarCloudScanHook.mjs +131 -93
- package/printing/index.js +1 -1
- package/printing/index.mjs +15 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancon/wildcat-utils",
|
|
3
|
-
"version": "1.54.0-check-optimizations.
|
|
3
|
+
"version": "1.54.0-check-optimizations.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.mjs",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -1025,6 +1025,11 @@
|
|
|
1025
1025
|
"require": "./preOrder/isPreOrderSharable.js",
|
|
1026
1026
|
"types": "./preOrder/isPreOrderSharable.d.ts"
|
|
1027
1027
|
},
|
|
1028
|
+
"./printing/StarScanConnection": {
|
|
1029
|
+
"import": "./printing/StarScanConnection.mjs",
|
|
1030
|
+
"require": "./printing/StarScanConnection.js",
|
|
1031
|
+
"types": "./printing/StarScanConnection.d.ts"
|
|
1032
|
+
},
|
|
1028
1033
|
"./printing/createStarCloudScanHook": {
|
|
1029
1034
|
"import": "./printing/createStarCloudScanHook.mjs",
|
|
1030
1035
|
"require": "./printing/createStarCloudScanHook.js",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { StarMonitor } from '@ancon/wildcat-printing';
|
|
2
|
+
export declare type StarScanLogger = {
|
|
3
|
+
info: (message: string, data?: Record<string, unknown>) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare enum StarScanReleaseReason {
|
|
6
|
+
/** A card was read, the scan is done */
|
|
7
|
+
CardRead = "CardRead",
|
|
8
|
+
/** The app went to the background */
|
|
9
|
+
Background = "Background",
|
|
10
|
+
/** The scan screen closed */
|
|
11
|
+
Unmount = "Unmount",
|
|
12
|
+
/** A new scan attempt replaced this one */
|
|
13
|
+
Restart = "Restart"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Owns the printer connection of one card scan screen.
|
|
17
|
+
*
|
|
18
|
+
* A Star printer accepts one connection at a time, and a card scan holds it
|
|
19
|
+
* for as long as it waits for a card. Another app on the device (POS and
|
|
20
|
+
* Express share devices and printers) cannot print meanwhile, so the
|
|
21
|
+
* connection is released when the app goes to the background and taken again
|
|
22
|
+
* when it returns.
|
|
23
|
+
*/
|
|
24
|
+
export default class StarScanConnection {
|
|
25
|
+
private logger?;
|
|
26
|
+
private monitor?;
|
|
27
|
+
private identifier?;
|
|
28
|
+
private scanAttempt;
|
|
29
|
+
private isBackground;
|
|
30
|
+
private isPausedForBackground;
|
|
31
|
+
constructor(logger?: StarScanLogger | undefined);
|
|
32
|
+
/**
|
|
33
|
+
* Starts a scan attempt. An earlier attempt that is still discovering the
|
|
34
|
+
* printer may no longer connect.
|
|
35
|
+
*/
|
|
36
|
+
beginScan(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Whether this is still the latest scan attempt. Results of an older
|
|
39
|
+
* attempt, such as a failed discover, must not change the screen.
|
|
40
|
+
*/
|
|
41
|
+
isLatest(scanAttempt: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the monitor is still the one this screen uses. Events and
|
|
44
|
+
* failures of a released or replaced monitor must not change the screen.
|
|
45
|
+
*/
|
|
46
|
+
isAttached(monitor: StarMonitor): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the scan attempt may connect to the printer now: it is the latest
|
|
49
|
+
* attempt and the app is in the foreground. An attempt held back by the
|
|
50
|
+
* background is started again when the app returns.
|
|
51
|
+
*/
|
|
52
|
+
mayConnect(scanAttempt: number): boolean;
|
|
53
|
+
/** Takes over a monitor that is about to connect, releasing any earlier one */
|
|
54
|
+
attach(monitor: StarMonitor, identifier: string): void;
|
|
55
|
+
/** Stops the monitor, which releases the printer connection */
|
|
56
|
+
release(reason: StarScanReleaseReason): void;
|
|
57
|
+
/**
|
|
58
|
+
* Call when the app moves between foreground and background. Returns true
|
|
59
|
+
* when a scan that was paused by the background should start again.
|
|
60
|
+
*
|
|
61
|
+
* @param isScanning - whether the screen is waiting for the printer or a card
|
|
62
|
+
*/
|
|
63
|
+
setBackground(isBackground: boolean, isScanning: boolean): boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var d=(s,t,e)=>t in s?c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var r=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var u=(s=>(s.CardRead="CardRead",s.Background="Background",s.Unmount="Unmount",s.Restart="Restart",s))(u||{});class g{constructor(t){r(this,"monitor");r(this,"identifier");r(this,"scanAttempt",0);r(this,"isBackground",!1);r(this,"isPausedForBackground",!1);this.logger=t}beginScan(){return this.scanAttempt+=1,this.isPausedForBackground=!1,this.scanAttempt}isLatest(t){return t===this.scanAttempt}isAttached(t){return this.monitor===t}mayConnect(t){return this.isLatest(t)?this.isBackground?(this.isPausedForBackground=!0,!1):!0:!1}attach(t,e){var i;this.release("Restart"),this.monitor=t,this.identifier=e,(i=this.logger)==null||i.info("Card scan connecting to printer",{identifier:e,sourceContext:"Printing"})}release(t){var a;const{monitor:e,identifier:i}=this;e&&(this.monitor=void 0,this.identifier=void 0,(a=this.logger)==null||a.info("Card scan released printer",{identifier:i,reason:t,sourceContext:"Printing"}),Promise.resolve(e.stop()).catch(n=>{var o;(o=this.logger)==null||o.info("Card scan release failed",{identifier:i,reason:t,error:(n==null?void 0:n.message)??String(n),sourceContext:"Printing"})}))}setBackground(t,e){if(t===this.isBackground)return!1;if(this.isBackground=t,t)return e&&(this.isPausedForBackground=!0),this.scanAttempt+=1,this.release("Background"),!1;const i=this.isPausedForBackground;return this.isPausedForBackground=!1,i}}exports.StarScanReleaseReason=u;exports.default=g;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var c = (i, t, s) => t in i ? u(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s;
|
|
3
|
+
var r = (i, t, s) => (c(i, typeof t != "symbol" ? t + "" : t, s), s);
|
|
4
|
+
var d = /* @__PURE__ */ ((i) => (i.CardRead = "CardRead", i.Background = "Background", i.Unmount = "Unmount", i.Restart = "Restart", i))(d || {});
|
|
5
|
+
class g {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
r(this, "monitor");
|
|
8
|
+
r(this, "identifier");
|
|
9
|
+
r(this, "scanAttempt", 0);
|
|
10
|
+
r(this, "isBackground", !1);
|
|
11
|
+
r(this, "isPausedForBackground", !1);
|
|
12
|
+
this.logger = t;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Starts a scan attempt. An earlier attempt that is still discovering the
|
|
16
|
+
* printer may no longer connect.
|
|
17
|
+
*/
|
|
18
|
+
beginScan() {
|
|
19
|
+
return this.scanAttempt += 1, this.isPausedForBackground = !1, this.scanAttempt;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether this is still the latest scan attempt. Results of an older
|
|
23
|
+
* attempt, such as a failed discover, must not change the screen.
|
|
24
|
+
*/
|
|
25
|
+
isLatest(t) {
|
|
26
|
+
return t === this.scanAttempt;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether the monitor is still the one this screen uses. Events and
|
|
30
|
+
* failures of a released or replaced monitor must not change the screen.
|
|
31
|
+
*/
|
|
32
|
+
isAttached(t) {
|
|
33
|
+
return this.monitor === t;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether the scan attempt may connect to the printer now: it is the latest
|
|
37
|
+
* attempt and the app is in the foreground. An attempt held back by the
|
|
38
|
+
* background is started again when the app returns.
|
|
39
|
+
*/
|
|
40
|
+
mayConnect(t) {
|
|
41
|
+
return this.isLatest(t) ? this.isBackground ? (this.isPausedForBackground = !0, !1) : !0 : !1;
|
|
42
|
+
}
|
|
43
|
+
/** Takes over a monitor that is about to connect, releasing any earlier one */
|
|
44
|
+
attach(t, s) {
|
|
45
|
+
var e;
|
|
46
|
+
this.release(
|
|
47
|
+
"Restart"
|
|
48
|
+
/* Restart */
|
|
49
|
+
), this.monitor = t, this.identifier = s, (e = this.logger) == null || e.info("Card scan connecting to printer", {
|
|
50
|
+
identifier: s,
|
|
51
|
+
sourceContext: "Printing"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Stops the monitor, which releases the printer connection */
|
|
55
|
+
release(t) {
|
|
56
|
+
var a;
|
|
57
|
+
const { monitor: s, identifier: e } = this;
|
|
58
|
+
s && (this.monitor = void 0, this.identifier = void 0, (a = this.logger) == null || a.info("Card scan released printer", {
|
|
59
|
+
identifier: e,
|
|
60
|
+
reason: t,
|
|
61
|
+
sourceContext: "Printing"
|
|
62
|
+
}), Promise.resolve(s.stop()).catch((n) => {
|
|
63
|
+
var o;
|
|
64
|
+
(o = this.logger) == null || o.info("Card scan release failed", {
|
|
65
|
+
identifier: e,
|
|
66
|
+
reason: t,
|
|
67
|
+
error: (n == null ? void 0 : n.message) ?? String(n),
|
|
68
|
+
sourceContext: "Printing"
|
|
69
|
+
});
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Call when the app moves between foreground and background. Returns true
|
|
74
|
+
* when a scan that was paused by the background should start again.
|
|
75
|
+
*
|
|
76
|
+
* @param isScanning - whether the screen is waiting for the printer or a card
|
|
77
|
+
*/
|
|
78
|
+
setBackground(t, s) {
|
|
79
|
+
if (t === this.isBackground)
|
|
80
|
+
return !1;
|
|
81
|
+
if (this.isBackground = t, t)
|
|
82
|
+
return s && (this.isPausedForBackground = !0), this.scanAttempt += 1, this.release(
|
|
83
|
+
"Background"
|
|
84
|
+
/* Background */
|
|
85
|
+
), !1;
|
|
86
|
+
const e = this.isPausedForBackground;
|
|
87
|
+
return this.isPausedForBackground = !1, e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
d as StarScanReleaseReason,
|
|
92
|
+
g as default
|
|
93
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ClientSettingsPrinter, DiscoveredStarPrinter } from '@ancon/wildcat-types';
|
|
2
2
|
import { StarCloudScanStatus } from './types';
|
|
3
|
+
import { type StarScanLogger } from './StarScanConnection';
|
|
3
4
|
declare type ReduxSelectorsArg<RootState = unknown> = {
|
|
4
5
|
selectedClientPrinterSelector: (state: RootState) => ClientSettingsPrinter | null;
|
|
5
6
|
};
|
|
@@ -8,6 +9,15 @@ declare type ReduxHooksArg<RootState = unknown> = {
|
|
|
8
9
|
getState: () => RootState;
|
|
9
10
|
};
|
|
10
11
|
useStarPrinterDiscover: () => (timeout: number) => Promise<DiscoveredStarPrinter[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the app is in the background (React Native AppState
|
|
14
|
+
* 'background'). When given, the printer connection is released while the
|
|
15
|
+
* app is in the background, so another app on the device can print, and
|
|
16
|
+
* the scan resumes on return.
|
|
17
|
+
*/
|
|
18
|
+
useIsAppInBackground?: () => boolean;
|
|
19
|
+
/** Logs when a scan takes and releases the printer connection */
|
|
20
|
+
logger?: StarScanLogger;
|
|
11
21
|
};
|
|
12
22
|
export declare type SanitizeRawOutputOptions = {
|
|
13
23
|
/** Enable or disable sanitization of raw output */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const a=require("react"),x=require("dayjs"),$=require("@ancon/wildcat-printing"),z=require("../shared/hooks/usePrevious.js"),O=require("../shared/hooks/useMountedRef.js"),n=require("./types.js"),A=require("./StarScanConnection.js"),tt=["TSP654"],nt=1,et=[n.StarCloudScanStatus.WaitingForPrinter,n.StarCloudScanStatus.PrinterDetected,n.StarCloudScanStatus.ReadyToScan];function rt(){return!1}function at(I,M,N,U,f){const{useAppStore:W,useStarPrinterDiscover:B,useIsAppInBackground:H=rt,logger:j}=M,{selectedClientPrinterSelector:G}=N;function J(){const t=O(),p=W(),b=B(),q=H(),y=a.useRef(null);y.current||(y.current=new A.default(j));const o=y.current,[i,K]=a.useState(I),[r,D]=a.useState(),[g,m]=a.useState(),L=z(g),[Q,k]=a.useState(),[V,T]=a.useState(U),c=a.useCallback(s=>{t!=null&&t.current&&K(s)},[t]),X=s=>{if((f==null?void 0:f.sanitizeEnabled)??!1){const u=(f==null?void 0:f.sanitizeRegex)??/[\D]/gi;return s.replace(u,"")}return s},w=a.useCallback(async s=>{o.release(A.StarScanReleaseReason.CardRead),c(n.StarCloudScanStatus.ScanningComplete);const d=String.fromCharCode(...s).trim(),u=X(d);T(u)},[c,o]),F=a.useCallback(async({macAddress:s,ipAddress:d})=>{let u;function S(e){return(...E)=>{u&&o.isAttached(u)&&e(...E)}}function v(e){c(n.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&k(e==null?void 0:e.message)}const P={onStarted:S(e=>{if(e&&e.inputDevicesCount>0){const{inputDevicesCount:E}=e;c(n.StarCloudScanStatus.ReadyToScan),D({inputDeviceCount:E,lastConnectedOn:new Date})}}),onStopped:S(e=>{e&&v(e),D(void 0)}),inputDevice:{onConnected:S(()=>{const e=((r==null?void 0:r.inputDeviceCount)||0)+1;c(e>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),D({inputDeviceCount:e,lastConnectedOn:new Date})}),onDisconnected:S(()=>{const e=((r==null?void 0:r.inputDeviceCount)||0)-1>=0?((r==null?void 0:r.inputDeviceCount)||0)-1:0;c(e>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),D({inputDeviceCount:e})}),onCommunicationError:S(v),onDataReceived:S(e=>m({data:e,lastReceivedOn:new Date}))}},l=d||s,C=$.monitor(l,P);if(u=C,o.attach(C,l),t!=null&&t.current)try{await C.start()}catch(e){if(!o.isAttached(C))return;c(n.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&k(e==null?void 0:e.message)}},[r,c,t,o]),h=a.useCallback(async()=>{const s=o.beginScan();t!=null&&t.current&&(c(n.StarCloudScanStatus.WaitingForPrinter),k(void 0),m(void 0),D(void 0),T(void 0));const d=G(p.getState()),{macAddress:u,serialNumber:S}=d;try{const P=(await b(2e3)).find(l=>u&&l.macAddress.toLowerCase()===u.toLowerCase()||S&&l.serialNumber===S);if(!o.mayConnect(s))return;if(t!=null&&t.current){if(P){if(tt.some(l=>{var C;return(C=P.model)==null?void 0:C.toLowerCase().includes(l.toLowerCase())})){c(n.StarCloudScanStatus.UnsupportedPrinter);return}F(P)}c(P?n.StarCloudScanStatus.PrinterDetected:n.StarCloudScanStatus.PrinterNotDetected)}}catch{if(!o.isLatest(s))return;t!=null&&t.current&&c(n.StarCloudScanStatus.PrinterNotDetected)}},[t,p,c,b,F,o]),R=a.useRef(i);R.current=i;const _=a.useRef(h);_.current=h,a.useEffect(()=>{o.setBackground(q,et.includes(R.current))&&(t!=null&&t.current)&&_.current()},[q,o,t]);const Y=i===n.StarCloudScanStatus.WaitingForPrinter||i===n.StarCloudScanStatus.PrinterDetected||i===n.StarCloudScanStatus.ReadyToScan||i===n.StarCloudScanStatus.ScanningComplete,Z=i===n.StarCloudScanStatus.PrinterNotDetected||i===n.StarCloudScanStatus.ScanFailed||i===n.StarCloudScanStatus.CommunicationError||i===n.StarCloudScanStatus.UnsupportedPrinter;return a.useEffect(()=>{if(!L&&(g==null?void 0:g.data)&&r&&(r!=null&&r.lastConnectedOn)){const{lastConnectedOn:d}=r,{lastReceivedOn:u,data:S}=g;x(u).diff(x(d),"second",!0)>nt?w(S):m(void 0)}},[g,L,r,w]),a.useEffect(()=>(i===n.StarCloudScanStatus.WaitingForPrinter&&h(),()=>{o.release(A.StarScanReleaseReason.Unmount)}),[]),{startScan:h,changeDeviceStatus:c,scanStatus:i,reading:V,connectionError:Q,isLoading:Y,isError:Z}}return J}module.exports=at;
|
|
@@ -1,138 +1,176 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import
|
|
3
|
-
import { monitor as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { StarCloudScanStatus as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { useRef as k, useState as D, useCallback as h, useEffect as L } from "react";
|
|
2
|
+
import W from "dayjs";
|
|
3
|
+
import { monitor as nn } from "@ancon/wildcat-printing";
|
|
4
|
+
import en from "../shared/hooks/usePrevious.mjs";
|
|
5
|
+
import tn from "../shared/hooks/useMountedRef.mjs";
|
|
6
|
+
import { StarCloudScanStatus as e } from "./types.mjs";
|
|
7
|
+
import rn, { StarScanReleaseReason as B } from "./StarScanConnection.mjs";
|
|
8
|
+
const on = ["TSP654"], cn = 1, sn = [
|
|
9
|
+
e.WaitingForPrinter,
|
|
10
|
+
e.PrinterDetected,
|
|
11
|
+
e.ReadyToScan
|
|
12
|
+
];
|
|
13
|
+
function an() {
|
|
14
|
+
return !1;
|
|
15
|
+
}
|
|
16
|
+
function mn(H, R, j, G, f) {
|
|
17
|
+
const {
|
|
18
|
+
useAppStore: q,
|
|
19
|
+
useStarPrinterDiscover: J,
|
|
20
|
+
useIsAppInBackground: K = an,
|
|
21
|
+
logger: Q
|
|
22
|
+
} = R, { selectedClientPrinterSelector: V } = j;
|
|
23
|
+
function X() {
|
|
24
|
+
const n = tn(), T = q(), F = J(), b = K(), p = k(null);
|
|
25
|
+
p.current || (p.current = new rn(Q));
|
|
26
|
+
const c = p.current, [s, Y] = D(H), [r, m] = D(), [C, y] = D(), w = en(C), [Z, A] = D(), [_, x] = D(G), o = h(
|
|
27
|
+
(i) => {
|
|
28
|
+
n != null && n.current && Y(i);
|
|
14
29
|
},
|
|
15
30
|
[n]
|
|
16
|
-
),
|
|
17
|
-
if ((
|
|
18
|
-
const
|
|
19
|
-
return
|
|
31
|
+
), $ = (i) => {
|
|
32
|
+
if ((f == null ? void 0 : f.sanitizeEnabled) ?? !1) {
|
|
33
|
+
const a = (f == null ? void 0 : f.sanitizeRegex) ?? /[\D]/gi;
|
|
34
|
+
return i.replace(a, "");
|
|
20
35
|
}
|
|
21
|
-
return
|
|
22
|
-
},
|
|
23
|
-
async (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
p(i);
|
|
36
|
+
return i;
|
|
37
|
+
}, I = h(
|
|
38
|
+
async (i) => {
|
|
39
|
+
c.release(B.CardRead), o(e.ScanningComplete);
|
|
40
|
+
const u = String.fromCharCode(...i).trim(), a = $(u);
|
|
41
|
+
x(a);
|
|
28
42
|
},
|
|
29
|
-
[o]
|
|
30
|
-
),
|
|
31
|
-
async ({ macAddress:
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
[o, c]
|
|
44
|
+
), M = h(
|
|
45
|
+
async ({ macAddress: i, ipAddress: u }) => {
|
|
46
|
+
let a;
|
|
47
|
+
function d(t) {
|
|
48
|
+
return (...E) => {
|
|
49
|
+
a && c.isAttached(a) && t(...E);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function P(t) {
|
|
53
|
+
o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
|
|
34
54
|
}
|
|
35
|
-
const
|
|
36
|
-
onStarted: (
|
|
37
|
-
if (
|
|
38
|
-
const { inputDevicesCount:
|
|
39
|
-
o(
|
|
40
|
-
inputDeviceCount:
|
|
55
|
+
const g = {
|
|
56
|
+
onStarted: d((t) => {
|
|
57
|
+
if (t && t.inputDevicesCount > 0) {
|
|
58
|
+
const { inputDevicesCount: E } = t;
|
|
59
|
+
o(e.ReadyToScan), m({
|
|
60
|
+
inputDeviceCount: E,
|
|
41
61
|
lastConnectedOn: /* @__PURE__ */ new Date()
|
|
42
62
|
});
|
|
43
63
|
}
|
|
44
|
-
},
|
|
45
|
-
onStopped: (
|
|
46
|
-
|
|
47
|
-
},
|
|
64
|
+
}),
|
|
65
|
+
onStopped: d((t) => {
|
|
66
|
+
t && P(t), m(void 0);
|
|
67
|
+
}),
|
|
48
68
|
inputDevice: {
|
|
49
|
-
onConnected: () => {
|
|
50
|
-
const
|
|
69
|
+
onConnected: d(() => {
|
|
70
|
+
const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
|
|
51
71
|
o(
|
|
52
|
-
|
|
53
|
-
),
|
|
54
|
-
inputDeviceCount:
|
|
72
|
+
t > 0 ? e.ReadyToScan : e.PrinterDetected
|
|
73
|
+
), m({
|
|
74
|
+
inputDeviceCount: t,
|
|
55
75
|
lastConnectedOn: /* @__PURE__ */ new Date()
|
|
56
76
|
});
|
|
57
|
-
},
|
|
58
|
-
onDisconnected: () => {
|
|
59
|
-
const
|
|
77
|
+
}),
|
|
78
|
+
onDisconnected: d(() => {
|
|
79
|
+
const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
|
|
60
80
|
o(
|
|
61
|
-
|
|
62
|
-
),
|
|
63
|
-
inputDeviceCount:
|
|
81
|
+
t > 0 ? e.ReadyToScan : e.PrinterDetected
|
|
82
|
+
), m({
|
|
83
|
+
inputDeviceCount: t
|
|
64
84
|
});
|
|
65
|
-
},
|
|
66
|
-
onCommunicationError:
|
|
67
|
-
onDataReceived: (
|
|
85
|
+
}),
|
|
86
|
+
onCommunicationError: d(P),
|
|
87
|
+
onDataReceived: d(
|
|
88
|
+
(t) => y({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
|
|
89
|
+
)
|
|
68
90
|
}
|
|
69
|
-
};
|
|
70
|
-
if (
|
|
91
|
+
}, l = u || i, S = nn(l, g);
|
|
92
|
+
if (a = S, c.attach(S, l), n != null && n.current)
|
|
71
93
|
try {
|
|
72
|
-
await
|
|
73
|
-
} catch (
|
|
74
|
-
|
|
94
|
+
await S.start();
|
|
95
|
+
} catch (t) {
|
|
96
|
+
if (!c.isAttached(S))
|
|
97
|
+
return;
|
|
98
|
+
o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
|
|
75
99
|
}
|
|
76
100
|
},
|
|
77
|
-
[r, o, n]
|
|
78
|
-
),
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
[r, o, n, c]
|
|
102
|
+
), v = h(async () => {
|
|
103
|
+
const i = c.beginScan();
|
|
104
|
+
n != null && n.current && (o(e.WaitingForPrinter), A(void 0), y(void 0), m(void 0), x(void 0));
|
|
105
|
+
const u = V(T.getState()), { macAddress: a, serialNumber: d } = u;
|
|
81
106
|
try {
|
|
82
|
-
const
|
|
83
|
-
(
|
|
107
|
+
const g = (await F(2e3)).find(
|
|
108
|
+
(l) => a && l.macAddress.toLowerCase() === a.toLowerCase() || d && l.serialNumber === d
|
|
84
109
|
);
|
|
110
|
+
if (!c.mayConnect(i))
|
|
111
|
+
return;
|
|
85
112
|
if (n != null && n.current) {
|
|
86
|
-
if (
|
|
87
|
-
if (
|
|
88
|
-
(
|
|
89
|
-
var
|
|
90
|
-
return (
|
|
113
|
+
if (g) {
|
|
114
|
+
if (on.some(
|
|
115
|
+
(l) => {
|
|
116
|
+
var S;
|
|
117
|
+
return (S = g.model) == null ? void 0 : S.toLowerCase().includes(l.toLowerCase());
|
|
91
118
|
}
|
|
92
119
|
)) {
|
|
93
|
-
o(
|
|
120
|
+
o(e.UnsupportedPrinter);
|
|
94
121
|
return;
|
|
95
122
|
}
|
|
96
|
-
|
|
123
|
+
M(g);
|
|
97
124
|
}
|
|
98
125
|
o(
|
|
99
|
-
|
|
126
|
+
g ? e.PrinterDetected : e.PrinterNotDetected
|
|
100
127
|
);
|
|
101
128
|
}
|
|
102
129
|
} catch {
|
|
103
|
-
|
|
130
|
+
if (!c.isLatest(i))
|
|
131
|
+
return;
|
|
132
|
+
n != null && n.current && o(e.PrinterNotDetected);
|
|
104
133
|
}
|
|
105
134
|
}, [
|
|
106
135
|
n,
|
|
107
|
-
|
|
136
|
+
T,
|
|
108
137
|
o,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
138
|
+
F,
|
|
139
|
+
M,
|
|
140
|
+
c
|
|
141
|
+
]), N = k(s);
|
|
142
|
+
N.current = s;
|
|
143
|
+
const U = k(v);
|
|
144
|
+
U.current = v, L(() => {
|
|
145
|
+
c.setBackground(
|
|
146
|
+
b,
|
|
147
|
+
sn.includes(N.current)
|
|
148
|
+
) && (n != null && n.current) && U.current();
|
|
149
|
+
}, [b, c, n]);
|
|
150
|
+
const z = s === e.WaitingForPrinter || s === e.PrinterDetected || s === e.ReadyToScan || s === e.ScanningComplete, O = s === e.PrinterNotDetected || s === e.ScanFailed || s === e.CommunicationError || s === e.UnsupportedPrinter;
|
|
151
|
+
return L(() => {
|
|
152
|
+
if (!w && (C == null ? void 0 : C.data) && r && (r != null && r.lastConnectedOn)) {
|
|
153
|
+
const { lastConnectedOn: u } = r, { lastReceivedOn: a, data: d } = C;
|
|
154
|
+
W(a).diff(
|
|
155
|
+
W(u),
|
|
117
156
|
"second",
|
|
118
157
|
!0
|
|
119
|
-
) >
|
|
158
|
+
) > cn ? I(d) : y(void 0);
|
|
120
159
|
}
|
|
121
|
-
}, [
|
|
122
|
-
|
|
123
|
-
(c = m.current) == null || c.stop();
|
|
160
|
+
}, [C, w, r, I]), L(() => (s === e.WaitingForPrinter && v(), () => {
|
|
161
|
+
c.release(B.Unmount);
|
|
124
162
|
}), []), {
|
|
125
|
-
startScan:
|
|
163
|
+
startScan: v,
|
|
126
164
|
changeDeviceStatus: o,
|
|
127
165
|
scanStatus: s,
|
|
128
|
-
reading:
|
|
129
|
-
connectionError:
|
|
130
|
-
isLoading:
|
|
131
|
-
isError:
|
|
166
|
+
reading: _,
|
|
167
|
+
connectionError: Z,
|
|
168
|
+
isLoading: z,
|
|
169
|
+
isError: O
|
|
132
170
|
};
|
|
133
171
|
}
|
|
134
|
-
return
|
|
172
|
+
return X;
|
|
135
173
|
}
|
|
136
174
|
export {
|
|
137
|
-
|
|
175
|
+
mn as default
|
|
138
176
|
};
|
package/printing/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");require("./StarScanConnection.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
|
package/printing/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { default as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as
|
|
1
|
+
import { default as f } from "./getPrinterType.mjs";
|
|
2
|
+
import { default as u } from "./isValidPrinter.mjs";
|
|
3
|
+
import { default as x } from "./isValidNetworkPrinter.mjs";
|
|
4
|
+
import { default as C } from "./isValidStarCloudPrinter.mjs";
|
|
5
|
+
import { default as V } from "./isTerminalPrinter.mjs";
|
|
6
|
+
import { default as k } from "./isCloudPrintModeEnabled.mjs";
|
|
7
|
+
import { default as b } from "./createStarCloudScanHook.mjs";
|
|
8
8
|
import "@ancon/wildcat-types";
|
|
9
9
|
import "react";
|
|
10
10
|
import "dayjs";
|
|
@@ -12,12 +12,13 @@ import "@ancon/wildcat-printing";
|
|
|
12
12
|
import "../shared/hooks/usePrevious.mjs";
|
|
13
13
|
import "../shared/hooks/useMountedRef.mjs";
|
|
14
14
|
import "./types.mjs";
|
|
15
|
+
import "./StarScanConnection.mjs";
|
|
15
16
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
b as createUseStarCloudScanHook,
|
|
18
|
+
f as getPrinterType,
|
|
19
|
+
k as isCloudPrintModeEnabled,
|
|
20
|
+
V as isTerminalPrinter,
|
|
21
|
+
x as isValidNetworkPrinter,
|
|
22
|
+
u as isValidPrinter,
|
|
23
|
+
C as isValidStarCloudPrinter
|
|
23
24
|
};
|