aboutsummaryrefslogtreecommitdiffstats
path: root/src/background
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 23:17:25 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 23:17:25 +0530
commit68777ec421d41be0da27013afd4165ae7d658d26 (patch)
tree4c1cc6af7acfeac54b2e54372944344d3f5b9a26 /src/background
parent20c3b38f24d79df8843f17985a7d13533d4e0d10 (diff)
downloadbanglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.tar.gz
banglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.zip
refactor: added linting with esling and also resolved warnings for it
Diffstat (limited to 'src/background')
-rw-r--r--src/background/run-ocr.ts18
1 files changed, 8 insertions, 10 deletions
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<void> {
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<void> {
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<OCRRequest, OCRResponse>({
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 });
}
})();