From 68777ec421d41be0da27013afd4165ae7d658d26 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 23:17:25 +0530 Subject: refactor: added linting with esling and also resolved warnings for it --- src/background/run-ocr.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/background') diff --git a/src/background/run-ocr.ts b/src/background/run-ocr.ts index 54c9e5f..683f701 100644 --- a/src/background/run-ocr.ts +++ b/src/background/run-ocr.ts @@ -1,3 +1,5 @@ +import { OCRRequest, OCRResponse } from "@/shared/ocr-request"; + const OFFSCREEN_DOCUMENT_PATH = "offscreen/ocr/index.html"; // Function to ensure the offscreen document is open @@ -5,7 +7,7 @@ const OFFSCREEN_DOCUMENT_PATH = "offscreen/ocr/index.html"; * Ensures the offscreen OCR document is open. If it already exists * this is a no-op. */ -async function setupOffscreenDocument() { +async function setupOffscreenDocument(): Promise { if (await chrome.offscreen.hasDocument()) { return; // Offscreen document already open } @@ -22,25 +24,21 @@ async function setupOffscreenDocument() { * image data URL to an offscreen document for Tesseract.js processing * and sends the recognised text back to the caller. */ -chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { +chrome.runtime.onMessage.addListener(function(message: OCRRequest, _sender, sendResponse): boolean { if (message.type === "OCR" && message.dataURL) { - (async () => { + void (async function(): Promise { try { // Ensure the offscreen document is open await setupOffscreenDocument(); // Send the OCR request to the offscreen document - const offscreenResponse = await chrome.runtime.sendMessage({ + const offscreenResponse = await chrome.runtime.sendMessage({ type: "OFFSCREEN_OCR_REQUEST", dataURL: message.dataURL }); - if (offscreenResponse && offscreenResponse.success) { - sendResponse(offscreenResponse); - } else { - sendResponse({ success: false, error: offscreenResponse?.error || "Unknown OCR error" }); - } - } catch (error) { + sendResponse(offscreenResponse); + } catch(error) { sendResponse({ success: false, error: (error as Error).message }); } })(); -- cgit v1.2.3