init commit
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
import { inRuntime, bridgeAsync } from "../bridge";
|
||||
import { isSupportWebScan, startScanForWeb, stopScanForWeb, isSupportImageScan, startScanForImage } from "../web";
|
||||
import { isSupportWebScan, startScanForWeb, stopScanForWeb, isSupportImageScan, startScanForImage, unlockScanBeep } from "../web";
|
||||
import { isSupportWxScan, startScanForWx } from "../wx";
|
||||
import { startScanner, stopScanner } from "../scanner";
|
||||
import { getConfig } from "../config";
|
||||
import { toAny } from "../../utils/toany";
|
||||
|
||||
let _scan_status = "closed";
|
||||
let _scan_status = "ready";
|
||||
let _scan_status_listener = null;
|
||||
let _scan_listener_list = [];
|
||||
let _scan_resolve = null;
|
||||
let _scan_closing = false;
|
||||
let _scan_next_start_time = 0;
|
||||
|
||||
const SCAN_RESTART_DELAY = 2000;
|
||||
const SCAN_RESTART_DELAY = 500;
|
||||
|
||||
function getScanRestartDelay() {
|
||||
return toAny(getConfig("scanRestartDelay"), SCAN_RESTART_DELAY);
|
||||
}
|
||||
|
||||
function __checkScanner() {
|
||||
if (_scan_listener_list.length > 0) {
|
||||
@@ -46,7 +51,7 @@ function __result(result) {
|
||||
}
|
||||
}
|
||||
if (matched) {
|
||||
_scan_next_start_time = Date.now() + SCAN_RESTART_DELAY;
|
||||
_scan_next_start_time = Date.now() + getScanRestartDelay();
|
||||
}
|
||||
return matched;
|
||||
}
|
||||
@@ -71,10 +76,10 @@ function __scanning() {
|
||||
}
|
||||
|
||||
function __closed() {
|
||||
if (_scan_status !== "closed") {
|
||||
_scan_status = "closed";
|
||||
if (_scan_status !== "ready") {
|
||||
_scan_status = "ready";
|
||||
if (_scan_status_listener) {
|
||||
_scan_status_listener({ status: "closed" });
|
||||
_scan_status_listener({ status: "ready" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,6 +337,7 @@ export function startScan() {
|
||||
scanPromise = __startWxScan();
|
||||
} else if (isSupportWebScan()) {
|
||||
console.log("startScanForWeb");
|
||||
unlockScanBeep();
|
||||
scanPromise = startScanForWeb(getConfig("webScanCanvasStyle"), __result);
|
||||
} else if (isSupportImageScan()) {
|
||||
console.log("startScanForImage");
|
||||
@@ -351,6 +357,10 @@ export function scanVideo() {
|
||||
console.log("Not support video scanner");
|
||||
return;
|
||||
}
|
||||
if (isScanning() || _scan_closing || Date.now() < _scan_next_start_time) {
|
||||
return;
|
||||
}
|
||||
unlockScanBeep();
|
||||
Promise.resolve().then(() => {
|
||||
__scanning();
|
||||
return startScanForWeb(getConfig("webScanCanvasStyle"), __result).then(resp => {
|
||||
|
||||
Reference in New Issue
Block a user