From 1714718522b0798ac9c32e33fe4b1687c1d5eec4 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Tue, 18 Oct 2022 08:45:58 +0200 Subject: [PATCH] #58 - Fixed crashes --- src/notes-index.ts | 2 +- src/pdf-manager.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/notes-index.ts b/src/notes-index.ts index 419f00f..bfc078c 100644 --- a/src/notes-index.ts +++ b/src/notes-index.ts @@ -84,7 +84,7 @@ export async function addToIndexAndCache(file: TAbstractFile): Promise { Search.minisearchInstance.add(note) cacheManager.addNoteToCache(note.path, note) } catch (e) { - console.trace('Error while indexing ' + file.basename) + // console.trace('Error while indexing ' + file.basename) console.error(e) } } diff --git a/src/pdf-manager.ts b/src/pdf-manager.ts index 9e0f301..24ea50e 100644 --- a/src/pdf-manager.ts +++ b/src/pdf-manager.ts @@ -2,6 +2,9 @@ import type { TFile } from 'obsidian' import PDFWorker from 'web-worker:./pdf-worker.ts' import { makeMD5 } from './utils' import { database } from './database' +import { settings } from './settings' + +const workerTimeout = 120_000 class PDFManager { public async getPdfText(file: TFile): Promise { @@ -28,6 +31,15 @@ class PDFManager { return new Promise(async (resolve, reject) => { // @ts-ignore file.stat.size + + // In case of a timeout, we just return an empty line. + // If we don't, it will try to reindex at each restart. + const timeout = setTimeout(() => { + worker.terminate() + console.warn('Omnisearch - Worker timeout to extract text from ' + file.basename) + resolve('') + }, workerTimeout) + worker.postMessage({ data, name: file.basename }) worker.onmessage = (evt: any) => { const text = (evt.data.text as string) @@ -39,8 +51,10 @@ class PDFManager { database.pdf .add({ hash, text, path: file.path, size: file.stat.size }) .then(() => { + clearTimeout(timeout) resolve(text) }) + worker.terminate() } }) }