Improve scanner repeatability guardrails

This commit is contained in:
AzuTear
2026-07-09 10:21:13 +02:00
parent 13fd46c104
commit c10f17b4ef
13 changed files with 356 additions and 39 deletions
+19 -1
View File
@@ -407,6 +407,12 @@ async function captureSourceFromGdi(sourceId: string, sourceName: string, option
}
function nativeImageFromGdiCapture(gdi: Awaited<ReturnType<InputHelperService["capturePrimaryScreenViaGdi"]>>) {
if (gdi.imageBase64) {
return nativeImage.createFromBuffer(Buffer.from(gdi.imageBase64, "base64"));
}
if (!gdi.dataUrl) {
throw new Error("GDI capture returned no image payload.");
}
return nativeImage.createFromDataURL(gdi.dataUrl);
}
@@ -1296,6 +1302,14 @@ async function buildCaptureResult(
const omitInventoryPreview = Boolean(options.omitInventoryPreview || options.ocrMode === "artifact");
const detailFingerprint = imageCropFingerprint(sourceImage, detailRect, size);
const inventoryFingerprint = imageCropFingerprint(sourceImage, inventoryRect, size);
const fastOcrPriority: Record<string, number> = {
"artifact-substats": 0,
"artifact-name": 1,
"artifact-footer": 2,
"artifact-slot": 3,
"artifact-main-stat-label": 4,
"artifact-level": 5,
};
const croppedPayload = crops
.filter((crop) => crop.ocrEnabled !== false)
.map((crop) => {
@@ -1307,7 +1321,11 @@ async function buildCaptureResult(
}
: null;
})
.filter((crop): crop is OcrCropPayload => Boolean(crop));
.filter((crop): crop is OcrCropPayload => Boolean(crop))
.sort((left, right) => {
if (options.ocrMode !== "artifact" || options.ocrProfile !== "fast") return 0;
return (fastOcrPriority[left.id] ?? 100) - (fastOcrPriority[right.id] ?? 100);
});
const prepareMs = Date.now() - buildStartedAt;
const ocrEngine = ocrEngineFromOptions(options);
const ocrStartedAt = Date.now();