Skip to content

Commit 9a468b9

Browse files
committed
refactor: Manual start recognize
1 parent 46f6592 commit 9a468b9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/windows/Ocr/components/OcrController/index.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import TranslateRoundedIcon from '@mui/icons-material/TranslateRounded';
2+
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';
23
import SyncRoundedIcon from '@mui/icons-material/SyncRounded';
34
import { Select, Button, MenuItem } from '@mui/material';
45
import { appWindow } from '@tauri-apps/api/window';
56
import { useTranslation } from 'react-i18next';
67
import { emit } from '@tauri-apps/api/event';
78
import 'flag-icons/css/flag-icons.min.css';
8-
import { atom, useAtom, useAtomValue } from 'jotai';
99
import { nanoid } from 'nanoid';
1010
import React from 'react';
1111
import * as ocrs from '../../../../interfaces_ocr';
@@ -16,10 +16,12 @@ import { useEffect } from 'react';
1616

1717
export const ocrInterfaceAtom = atom('tesseract');
1818
export const ocrLanguageAtom = atom('en');
19+
export const ocrStartFlagAtom = atom();
1920

2021
export default function OcrController() {
2122
const [ocrInterface, setOcrInterface] = useAtom(ocrInterfaceAtom);
2223
const [ocrLanguage, setOcrLanguage] = useAtom(ocrLanguageAtom);
24+
const setOcrStartFlag = useSetAtom(ocrStartFlagAtom);
2325
const resultText = useAtomValue(resultTextAtom);
2426
const { t } = useTranslation();
2527

@@ -84,6 +86,9 @@ export default function OcrController() {
8486
variant='outlined'
8587
sx={{ width: 160, textTransform: 'none' }}
8688
startIcon={<SyncRoundedIcon />}
89+
onClick={() => {
90+
setOcrStartFlag(nanoid());
91+
}}
8792
>
8893
{t('ocr.recognize')}
8994
</Button>

src/windows/Ocr/components/TextArea/index.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useTheme } from '@mui/material/styles';
88
import { useTranslation } from 'react-i18next';
99
import { atom, useAtom, useAtomValue } from 'jotai';
1010
import { nanoid } from 'nanoid';
11-
import { ocrInterfaceAtom, ocrLanguageAtom } from '../OcrController';
11+
import { ocrInterfaceAtom, ocrLanguageAtom, ocrStartFlagAtom } from '../OcrController';
1212
import * as ocrs from '../../../../interfaces_ocr';
1313
import { imgUrlAtom } from '../ImageArea';
1414
import './style.css';
@@ -22,6 +22,7 @@ export default function TextArea() {
2222
const imgUrl = useAtomValue(imgUrlAtom);
2323
const ocrLanguage = useAtomValue(ocrLanguageAtom);
2424
const ocrInterface = useAtomValue(ocrInterfaceAtom);
25+
const ocrStartFlag = useAtomValue(ocrStartFlagAtom);
2526
const { t } = useTranslation();
2627
const theme = useTheme();
2728

@@ -54,7 +55,7 @@ export default function TextArea() {
5455
}
5556
);
5657
}
57-
}, [imgUrl, ocrInterface, ocrLanguage]);
58+
}, [imgUrl, ocrInterface, ocrLanguage, ocrStartFlag]);
5859

5960
return (
6061
<>

0 commit comments

Comments
 (0)