实现 tesseract 的核心部分打包

This commit is contained in:
锦恢 2025-05-03 02:26:21 +08:00
parent 1c92b6fddd
commit 8f8106a0a3
3 changed files with 18 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import { routeMessage } from './common/router';
import { VSCodeWebViewLike } from './hook/adapter';
import path from 'node:path';
import * as fs from 'node:fs';
import { setRunningCWD } from './hook/setting';
export interface VSCodeMessage {
command: string;
@ -94,6 +95,9 @@ function updateConnectionOption(data: any) {
}
}
const devHome = path.join(__dirname, '..', '..');
setRunningCWD(devHome);
wss.on('connection', ws => {
// 仿造 webview 进行统一接口访问

View File

@ -47,6 +47,12 @@ export async function tesseractOCR(
logger: (message: Tesseract.LoggerMessage) => void,
lang: string = 'eng+chi_sim'
) {
const ocrHome = path.join(RUNNING_CWD, 'resources', 'ocr');
if (!ocrHome) {
console.log('ocr 目录不存在');
return '安装包已经损坏';
}
try {
const { data: { text } } = await Tesseract.recognize(
@ -54,10 +60,10 @@ export async function tesseractOCR(
lang,
{
logger,
langPath: './',
gzip: false,
cacheMethod: 'cache',
cachePath: RUNNING_CWD
langPath: ocrHome,
corePath: ocrHome,
workerPath: path.join(ocrHome, 'worker.js'),
}
);

View File

@ -14,8 +14,9 @@ export class HookController {
console.log('test ocr begin');
const cachePath = context.extensionPath;
const workerPath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.js');
const corePath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.wasm');
const workerPath = path.join(cachePath, 'resources', 'ocr', 'worker.js');
const corePath = path.join(cachePath, 'resources', 'ocr');
const langPath = path.join(cachePath,'resources', 'ocr');
console.log('workerPath', workerPath);
console.log('corePath', corePath);
@ -26,10 +27,8 @@ export class HookController {
'eng+chi_sim',
{
logger: (m) => console.log(m),
langPath: './',
langPath,
gzip: false,
cacheMethod: 'cache',
cachePath,
workerPath,
corePath
}