#4221 Scanner - Adapter sind nicht bereit

(cherry picked from commit 78e76818b5)
(cherry picked from commit 44b406fad4)
This commit is contained in:
Lorenz Hilpert
2023-07-25 14:52:18 +02:00
parent a442a50708
commit 141c7fe1d6
2 changed files with 9 additions and 32 deletions

View File

@@ -14,7 +14,6 @@ export class ScanAdapterService {
async init(): Promise<void> {
for (const adapter of this.scanAdapters) {
const isReady = await adapter.init();
console.log('ScanAdapterService.init', adapter.name, isReady);
this._readyAdapters[adapter.name] = isReady;
}
}
@@ -24,52 +23,30 @@ export class ScanAdapterService {
}
getAdapter(name: string): ScanAdapter | undefined {
return this.scanAdapters.find((adapter) => adapter.name === name);
return this._readyAdapters[name] && this.scanAdapters.find((adapter) => adapter.name === name);
}
// return true if at least one adapter is ready
isReady(): boolean {
return Object.values(this._readyAdapters).some((ready) => ready);
}
scan(ops: { use?: string; include?: string[]; exclude?: string[] } = {}): Observable<string> {
scan(): Observable<string> {
const adapterOrder = ['Native', 'Scandit', 'Dev'];
let adapter: ScanAdapter;
if (ops.use == undefined) {
const adapterOrder = ['Native', 'Scandit', 'Dev'];
for (const name of adapterOrder) {
adapter = this.getAdapter(name);
for (const name of adapterOrder) {
adapter = this.getAdapter(name);
if (adapter) {
break;
}
if (adapter) {
break;
}
// get the first adapter that is ready to use
// adapter = this.scanAdapters
// .filter((adapter) => {
// if (ops.include?.length) {
// return ops.include.includes(adapter.name);
// } else if (ops.exclude?.length) {
// return !ops.exclude.includes(adapter.name);
// } else {
// return true;
// }
// })
// .find((adapter) => this._readyAdapters[adapter.name]);
} else {
adapter = this.getAdapter(ops.use);
}
if (!adapter) {
return throwError('No adapter found');
}
if (this._readyAdapters[adapter.name] == false) {
return throwError('Adapter is not ready');
}
return adapter.scan();
}
}

View File

@@ -89,7 +89,7 @@
"moment": "^2.29.4",
"ng2-pdf-viewer": "^9.1.3",
"rxjs": "^6.6.7",
"scandit-sdk": "^5.12.1",
"scandit-sdk": "^5.13.2",
"socket.io": "^4.5.4",
"tslib": "^2.0.0",
"uglify-js": "^3.4.9",