mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
feat: 添加OCR提供者钩子函数
实现useOcrProvider钩子用于获取和更新OCR提供者配置
This commit is contained in:
parent
0be8b73ccf
commit
5ee7718054
30
src/renderer/src/hooks/useOcrProvider.ts
Normal file
30
src/renderer/src/hooks/useOcrProvider.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { loggerService } from '@logger'
|
||||
import { useAppSelector } from '@renderer/store'
|
||||
import { updateOcrProviderConfig } from '@renderer/store/ocr'
|
||||
import { OcrProviderConfig } from '@renderer/types'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useDispatch } from 'react-redux'
|
||||
|
||||
const logger = loggerService.withContext('useOcrProvider')
|
||||
|
||||
export const useOcrProvider = (id: string) => {
|
||||
const { t } = useTranslation()
|
||||
const dispatch = useDispatch()
|
||||
const providers = useAppSelector((state) => state.ocr.providers)
|
||||
const provider = providers.find((p) => p.id === id)
|
||||
|
||||
if (!provider) {
|
||||
logger.error(`Ocr Provider ${id} not found`)
|
||||
window.message.error(t('ocr.provider.not_found'))
|
||||
throw new Error(`Ocr Provider ${id} not found`)
|
||||
}
|
||||
|
||||
const updateConfig = (update: Partial<OcrProviderConfig>) => {
|
||||
dispatch(updateOcrProviderConfig({ id: provider.id, update }))
|
||||
}
|
||||
|
||||
return {
|
||||
provider,
|
||||
updateConfig
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user