11// Interface for barcode functions.
22
3- const DL_BARCODE_MGR_VER = 1 ;
3+ const DL_BARCODE_MGR_VER = 2 ;
44
55class DLBcdMgr {
6+
7+ /**
8+ * Private method to return an instance of DLBarcodeMgr.
9+ * @returns {DLBcdMgr } An instance of DLBcdMgr.
10+ * @throws {ReferenceError } If _DLBarcodeMgr is not injected by Datalogic Enterprise Browser.
11+ */
12+ #getDLBarcodeMgr( ) {
13+ try {
14+ return _DLBarcodeMgr ;
15+ } catch ( e ) {
16+ throw ReferenceError ( "_DLBarcodeMgr has not been injected by Datalogic Enterprise Browser" ) ;
17+ }
18+ }
19+
620 /**
721 * Private method to return the appropriate type.
822 * @param {string } text A String with a prefixed type and value.
@@ -39,7 +53,7 @@ class DLBcdMgr {
3953 * @returns {any } The current value of the given id.
4054 */
4155 getProperty ( id ) {
42- return this . #getType( _DLBarcodeMgr . getProperty ( id ) ) ;
56+ return this . #getType( this . #getDLBarcodeMgr ( ) . getProperty ( id ) ) ;
4357 }
4458
4559 /**
@@ -50,10 +64,17 @@ class DLBcdMgr {
5064 */
5165 setProperty ( id , value ) {
5266 if ( typeof value === "string" ) {
53- return _DLBarcodeMgr . setPropertyString ( id , value ) ;
67+ return this . #getDLBarcodeMgr( ) . setPropertyString ( id , value ) ;
68+ }
69+ else if ( typeof value === "boolean" ) {
70+ if ( value ) {
71+ return this . #getDLBarcodeMgr( ) . setPropertyInt ( id , 1 ) ;
72+ } else {
73+ return this . #getDLBarcodeMgr( ) . setPropertyInt ( id , 0 ) ;
74+ }
5475 }
5576 else {
56- return _DLBarcodeMgr . setPropertyInt ( id , value ) ;
77+ return this . #getDLBarcodeMgr ( ) . setPropertyInt ( id , value ) ;
5778 }
5879 }
5980
@@ -83,7 +104,7 @@ class DLBcdMgr {
83104 * @returns {boolean } True if property is available.
84105 */
85106 isAvailable ( id ) {
86- return _DLBarcodeMgr . isAvailable ( id ) ;
107+ return this . #getDLBarcodeMgr ( ) . isAvailable ( id ) ;
87108 }
88109
89110 /**
@@ -92,7 +113,7 @@ class DLBcdMgr {
92113 * @returns {any } The minimum value of the property.
93114 */
94115 getMin ( id ) {
95- return this . #getType( _DLBarcodeMgr . getMin ( id ) ) ;
116+ return this . #getType( this . #getDLBarcodeMgr ( ) . getMin ( id ) ) ;
96117 }
97118
98119 /**
@@ -101,15 +122,15 @@ class DLBcdMgr {
101122 * @returns {any } The maximum value of the property.
102123 */
103124 getMax ( id ) {
104- return this . #getType( _DLBarcodeMgr . getMax ( id ) ) ;
125+ return this . #getType( this . #getDLBarcodeMgr ( ) . getMax ( id ) ) ;
105126 }
106127
107128 /**
108129 * Commit decode properties to be saved in a persistent way across system reboot.
109130 * @returns {boolean } True if barcode properties have been successfully committed.
110131 */
111132 commitProperties ( ) {
112- return _DLBarcodeMgr . commitProperties ( ) ;
133+ return this . #getDLBarcodeMgr ( ) . commitProperties ( ) ;
113134 }
114135
115136 /**
@@ -118,35 +139,35 @@ class DLBcdMgr {
118139 * @returns {boolean } True if all symbologies have been successfully enabled/disabled.
119140 */
120141 enableAllSymbologies ( enable ) {
121- return _DLBarcodeMgr . enableAllSymbologies ( enable ) ;
142+ return this . #getDLBarcodeMgr ( ) . enableAllSymbologies ( enable ) ;
122143 }
123144
124145 /**
125146 * Set decode properties to system defaults.
126147 * @returns {boolean } True if all decode properties have been successfully set to default values.
127148 */
128149 setDefaults ( ) {
129- return _DLBarcodeMgr . setDefaults ( ) ;
150+ return this . #getDLBarcodeMgr ( ) . setDefaults ( ) ;
130151 }
131152
132153 /**
133154 * Checks if the Scanner Service is correctly initialized.
134155 * @returns {boolean } True if the Scanner Service is correctly initialized.
135156 */
136157 isInitialized ( ) {
137- return _DLBarcodeMgr . isInitialized ( ) ;
158+ return this . #getDLBarcodeMgr ( ) . isInitialized ( ) ;
138159 }
139160
140161 /**
141- * Attach a callback function to the scan event.
162+ * Attach a callback function to the scan event.
142163 * @param {(scan: {id: number, rawData: string, text: string}) => void } callback function to be called when a scan event occurs. Scan results passed as an argument with the following parameters:
143164 * * id - Represents the scanned symbology. Name of symbology can be retrieved from the {@link SymIds} object.
144165 * * rawData - Byte data from the scan.
145166 * * text - The readable text of the barcode scanned.
146167 * @returns {boolean } True if a scan listener has been successfully added.
147168 */
148169 onScan ( callback ) {
149- let success = _DLBarcodeMgr . addReadListener ( ) ;
170+ let success = this . #getDLBarcodeMgr ( ) . addReadListener ( ) ;
150171 window . addEventListener ( 'scan' , function ( event ) {
151172 callback ( event . detail . scan ) ;
152173 } ) ;
@@ -158,7 +179,7 @@ class DLBcdMgr {
158179 * @returns {boolean } True if the read listener has been successfully removed.
159180 */
160181 ignoreScan ( ) {
161- return _DLBarcodeMgr . removeReadListener ( ) ;
182+ return this . #getDLBarcodeMgr ( ) . removeReadListener ( ) ;
162183 }
163184
164185 /**
@@ -167,7 +188,7 @@ class DLBcdMgr {
167188 * @returns {boolean } True if a timeout listener has been successfully added.
168189 */
169190 onTimeout ( callback ) {
170- let success = _DLBarcodeMgr . addTimeoutListener ( ) ;
191+ let success = this . #getDLBarcodeMgr ( ) . addTimeoutListener ( ) ;
171192 window . addEventListener ( 'timeout' , callback ) ;
172193 return success ;
173194 }
@@ -177,7 +198,7 @@ class DLBcdMgr {
177198 * @returns {boolean } True if the timeout listener has been successfully removed.
178199 */
179200 ignoreTimeout ( ) {
180- return _DLBarcodeMgr . removeTimeoutListener ( ) ;
201+ return this . #getDLBarcodeMgr ( ) . removeTimeoutListener ( ) ;
181202 }
182203
183204 /**
@@ -187,10 +208,10 @@ class DLBcdMgr {
187208 */
188209 startDecode ( timeout ) {
189210 if ( typeof timeout === 'undefined' ) {
190- return _DLBarcodeMgr . startDecode ( 5000 ) ;
211+ return this . #getDLBarcodeMgr ( ) . startDecode ( 5000 ) ;
191212 }
192213 else {
193- return _DLBarcodeMgr . startDecode ( timeout ) ;
214+ return this . #getDLBarcodeMgr ( ) . startDecode ( timeout ) ;
194215 }
195216 }
196217
@@ -199,7 +220,7 @@ class DLBcdMgr {
199220 * @returns {boolean } True if decoding has successfully stopped, or the scanner is not actively decoding.
200221 */
201222 stopDecode ( ) {
202- return _DLBarcodeMgr . stopDecode ( ) ;
223+ return this . #getDLBarcodeMgr ( ) . stopDecode ( ) ;
203224 }
204225} ;
205226
0 commit comments