From 589fac27e76876ff18d7cbabe8d1570ff8abc48c Mon Sep 17 00:00:00 2001
From: troyeguo <13820674+troyeguo@users.noreply.github.com>
Date: Mon, 13 Jul 2026 14:38:24 +0800
Subject: [PATCH] feat: implement default OCR engine and language selection
logic in ConvertDialog and Viewer components
---
.../dialogs/convertDialog/component.tsx | 81 ++++---------------
src/containers/viewer/component.tsx | 34 +++-----
src/utils/common.ts | 68 ++++++++++++++++
3 files changed, 94 insertions(+), 89 deletions(-)
diff --git a/src/components/dialogs/convertDialog/component.tsx b/src/components/dialogs/convertDialog/component.tsx
index d3558cc6..19112336 100644
--- a/src/components/dialogs/convertDialog/component.tsx
+++ b/src/components/dialogs/convertDialog/component.tsx
@@ -6,13 +6,13 @@ import "./convertDialog.css";
import { ConfigService } from "../../../assets/lib/kookit-extra-browser.min";
import BookUtil from "../../../utils/file/bookUtil";
import {
- getOcrPaddleLangList,
ocrEngineList,
ocrTesseractLangList,
paraSpacingList,
titleSizeList,
} from "../../../constants/dropdownList";
import toast from "react-hot-toast";
+import { getDefaultOcrEngine, getOcrLangList } from "../../../utils/common";
class ConvertDialog extends React.Component<
ConvertDialogProps,
@@ -27,36 +27,7 @@ class ConvertDialog extends React.Component<
),
};
}
- getLangList = (engine: string) => {
- let list: any[];
- if (engine === "tesseract") {
- list = ocrTesseractLangList;
- } else if (engine === "official-ai-ocr") {
- list = [
- {
- label: "General",
- value: "general",
- lang: "general",
- },
- {
- label: "Accurate",
- value: "accurate",
- lang: "accurate",
- },
- ];
- } else if (engine === "system-ocr") {
- list = [
- {
- label: "Auto",
- value: "auto",
- lang: "auto",
- },
- ];
- } else {
- list = getOcrPaddleLangList();
- }
- return list;
- };
+
renderSwitchOption = (optionList: any[]) => {
return optionList.map((item) => {
return (
@@ -170,16 +141,7 @@ class ConvertDialog extends React.Component<
{this.props.currentBook.description.indexOf("scanned") === -1 &&
@@ -407,7 +361,7 @@ class ConvertDialog extends React.Component<
);
const currentLang = ConfigService.getReaderConfig("lang");
- const match = this.getLangList(engine).find(
+ const match = getOcrLangList(engine).find(
(o: any) => o.lang === currentLang
);
return match ? match.value : "";
@@ -431,13 +385,8 @@ class ConvertDialog extends React.Component<
>
{[
{ label: "Please select", value: "", lang: "" },
- ...(this.getLangList(
- ConfigService.getReaderConfig(
- this.props.currentBook.description.indexOf("scanned") >
- -1
- ? "scannedOcrEngine"
- : "textOcrEngine"
- )
+ ...(getOcrLangList(
+ getDefaultOcrEngine(this.props.currentBook)
) || []),
].map((item) => (