(pdfFiles, isProcessing)
| 123 | } |
| 124 | |
| 125 | function updateProcessButtonState(pdfFiles, isProcessing) { |
| 126 | if (!processBtn) return; |
| 127 | const getActiveFiles = typeof global.getActiveFiles === 'function' ? global.getActiveFiles : null; |
| 128 | const effectiveFiles = getActiveFiles ? getActiveFiles() : pdfFiles; |
| 129 | let ocrConfigAvailable = true; // 重命名:更清晰地表示 OCR 配置是否可用 |
| 130 | let translationKeysAvailable = true; |
| 131 | const hasPdfFiles = effectiveFiles.some(file => file.name.toLowerCase().endsWith('.pdf')); |
| 132 | |
| 133 | // 检查 OCR 引擎与所需配置 |
| 134 | let ocrEngine = 'mistral'; |
| 135 | let ocrConfigValid = true; |
| 136 | let ocrConfigMessage = ''; |
| 137 | try { |
| 138 | if (window.ocrSettingsManager && typeof window.ocrSettingsManager.getCurrentConfig === 'function') { |
| 139 | ocrEngine = window.ocrSettingsManager.getCurrentConfig().engine || (localStorage.getItem('ocrEngine') || 'mistral'); |
| 140 | // 使用 validateConfig 检查配置是否完整 |
| 141 | const validation = window.ocrSettingsManager.validateConfig(); |
| 142 | ocrConfigValid = validation.valid; |
| 143 | ocrConfigMessage = validation.message; |
| 144 | } else { |
| 145 | ocrEngine = localStorage.getItem('ocrEngine') || 'mistral'; |
| 146 | } |
| 147 | } catch {} |
| 148 | |
| 149 | if (hasPdfFiles) { |
| 150 | if (ocrEngine === 'none') { |
| 151 | // 选择了"不需要 OCR"但有 PDF 文件,标记为无效 |
| 152 | ocrConfigAvailable = false; |
| 153 | } else if (!ocrConfigValid) { |
| 154 | // 当前选择的 OCR 引擎配置不完整 |
| 155 | ocrConfigAvailable = false; |
| 156 | } else { |
| 157 | // OCR 配置有效 |
| 158 | ocrConfigAvailable = true; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // 检查翻译 Keys(如果需要翻译)- 直接使用 app.js 的逻辑 |
| 163 | const settings = typeof global.loadSettings === 'function' ? global.loadSettings() : {}; |
| 164 | const selectedTranslationModelName = settings.selectedTranslationModel || 'none'; |
| 165 | let translationModelDisplayName = selectedTranslationModelName; |
| 166 | let currentTranslationModelForProvider = null; |
| 167 | let translationModelConfigForProcess = null; |
| 168 | |
| 169 | if (selectedTranslationModelName !== 'none') { |
| 170 | if (selectedTranslationModelName === 'custom') { |
| 171 | const selectedCustomSourceId = settings.selectedCustomSourceSiteId; |
| 172 | if (!selectedCustomSourceId) { |
| 173 | translationKeysAvailable = false; |
| 174 | } else { |
| 175 | const allSourceSites = typeof global.loadAllCustomSourceSites === 'function' ? global.loadAllCustomSourceSites() : {}; |
| 176 | const siteConfig = allSourceSites[selectedCustomSourceId]; |
| 177 | if (!siteConfig) { |
| 178 | translationKeysAvailable = false; |
| 179 | } else { |
| 180 | currentTranslationModelForProvider = `custom_source_${selectedCustomSourceId}`; |
| 181 | translationModelConfigForProcess = siteConfig; |
| 182 | translationModelDisplayName = siteConfig.displayName || siteConfig.name || selectedCustomSourceId; |
no test coverage detected