This commit is contained in:
iqudoo
2026-05-26 05:14:22 +08:00
parent cdec1838ac
commit 229c8cb9e4
3 changed files with 16 additions and 3 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -19,6 +19,7 @@ import {
setEmbedScanResultForwarder, setEmbedScanResultForwarder,
setEmbedScanErrorForwarder, setEmbedScanErrorForwarder,
} from "./services/embedScanBridge"; } from "./services/embedScanBridge";
import { unlockScanBeep, installScanBeepGestureUnlock } from "./services/web";
const EMBED_SOURCE = "IScanEmbed"; const EMBED_SOURCE = "IScanEmbed";
const EMBED_V = 1; const EMBED_V = 1;
@@ -34,6 +35,13 @@ const EMBED_LISTENER_METHODS = new Set([
"clear", "clear",
]); ]);
/** 嵌入 iframe 转发到父页时,须在子页用用户手势解锁提示音 */
const EMBED_SCAN_GESTURE_METHODS = new Set([
"startScan",
"scanImage",
"scanImageFromFile",
]);
function isEmbedMessage(data) { function isEmbedMessage(data) {
return data && data.source === EMBED_SOURCE && data.v === EMBED_V; return data && data.source === EMBED_SOURCE && data.v === EMBED_V;
} }
@@ -256,6 +264,7 @@ function ensureEmbedChildListener() {
return; return;
} }
embedChildInstalled = true; embedChildInstalled = true;
installScanBeepGestureUnlock();
window.addEventListener("message", embedChildOnMessage); window.addEventListener("message", embedChildOnMessage);
} }
@@ -449,6 +458,9 @@ function createInvokeTransport(lib, method, methodName, initNames) {
} }
return _exec(lib, methodName, ...params); return _exec(lib, methodName, ...params);
} }
if (EMBED_SCAN_GESTURE_METHODS.has(method)) {
unlockScanBeep();
}
return embedInvoke(methodName, params); return embedInvoke(methodName, params);
} }
if (!isReadyCalled() && initNames && initNames.indexOf(method) < 0) { if (!isReadyCalled() && initNames && initNames.indexOf(method) < 0) {

View File

@@ -887,7 +887,7 @@ function resetScanBeepPlayback(audio) {
} }
} }
function installScanBeepGestureUnlock() { export function installScanBeepGestureUnlock() {
if (scanBeepGestureUnlockInstalled || typeof document === "undefined" || !isScanBeepEnabled()) { if (scanBeepGestureUnlockInstalled || typeof document === "undefined" || !isScanBeepEnabled()) {
return; return;
} }
@@ -1774,7 +1774,8 @@ export function startScanForWeb(onResult, onError) {
return; return;
} }
unlockScanBeep(); unlockScanBeep();
chooseImageFile().then(file => { // 扫码页内选图按钮:直接调起系统文件选择,不走 webScanImagePickerMode 的说明弹窗
chooseImageFile({ mode: "auto" }).then(file => {
if (!file || scanWeb.uuid !== currentUuid || closed) { if (!file || scanWeb.uuid !== currentUuid || closed) {
return; return;
} }