From b5c4e3d23d84eb8292e224afdf6d40fed1597ae4 Mon Sep 17 00:00:00 2001 From: Alexis Rondeau Date: Wed, 13 Jan 2021 11:28:38 +0100 Subject: [PATCH] Disables plugin temporarily and shows a modal instead --- manifest.json | 4 +-- src/PDFAnnotationsManager.ts | 8 ++--- src/main.ts | 69 ++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/manifest.json b/manifest.json index 2a702cc..92a2c6e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { "id": "obsidian-extract-pdf-highlights", "name": "PDF Highlights", - "version": "0.0.2", + "version": "0.0.3", "minAppVersion": "0.9.12", - "description": "Extract highlights, underlines and annotations from your PDFs into Obsidian", + "description": "[Currently disabled] Extract highlights, underlines and annotations from your PDFs into Obsidian", "author": "Alexis Rondeau", "authorUrl": "https://publish.obsidian.md/alexisrondeau", "isDesktopOnly": false diff --git a/src/PDFAnnotationsManager.ts b/src/PDFAnnotationsManager.ts index 3ad78ff..6813fff 100644 --- a/src/PDFAnnotationsManager.ts +++ b/src/PDFAnnotationsManager.ts @@ -1,5 +1,5 @@ -import pdfjsCustom from "node_modules/pdfjs-dist/build/pdf"; -import worker from "node_modules/pdfjs-dist/build/pdf.worker.entry"; +import * as customPDFJS from "node_modules/pdfjs-dist/build/pdf"; +import * as customPDFJSWorker from "node_modules/pdfjs-dist/build/pdf.worker.entry"; var finalHighlightsAnnotations = new Array(); @@ -7,13 +7,13 @@ export default class PDFAnnotationsManager { async fetchRawAnnotationsFromPDF(arrayBuffer) { - pdfjsCustom.GlobalWorkerOptions.workerSrc = worker; + customPDFJS.GlobalWorkerOptions.workerSrc = customPDFJSWorker; finalHighlightsAnnotations = new Array(); var SUPPORTED_ANNOTS = ['Text', 'Highlight', 'Underline']; - var loadingTask = pdfjsCustom.getDocument(arrayBuffer); + var loadingTask = customPDFJS.getDocument(arrayBuffer); return await loadingTask.promise .then(function (doc) { diff --git a/src/main.ts b/src/main.ts index f16eec0..20444a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,13 @@ -import { Plugin } from 'obsidian'; +import {App, Modal, Plugin} from 'obsidian'; import ExtractPDFHighlightsPluginSettings from "./ExtractPDFHighlightsPluginSettings"; import ExtractPDFHighlightsPluginSettingsTab from "./ExtractPDFHighlightsPluginSettingsTab"; -import PDFAnnotationsManager from "./PDFAnnotationsManager"; +// import PDFAnnotationsManager from "./PDFAnnotationsManager"; export default class ExtractPDFHighlightsPlugin extends Plugin { public settings: ExtractPDFHighlightsPluginSettings; + private modal: ProgressModal; async onload() { this.loadSettings(); @@ -19,27 +20,30 @@ export default class ExtractPDFHighlightsPlugin extends Plugin { onunload() {} async processPDFHighlights() { - let file = this.app.workspace.getActiveFile(); - - if (file === null) return; - if (file.extension !== 'pdf') return; - - let arrayBuffer = await this.app.vault.readBinary(file); - let pdfAnnotationsManager = new PDFAnnotationsManager(); - - let rawAnnotationsFromPDF = await pdfAnnotationsManager.fetchRawAnnotationsFromPDF(arrayBuffer); - let filteredAnnotations = pdfAnnotationsManager.filterRawAnnotations(rawAnnotationsFromPDF); - let groupedAnnotationsByPageMap = pdfAnnotationsManager.groupAnnotationsByPage(filteredAnnotations); - let sortedAnnotationsByPositionGroupedByPage = pdfAnnotationsManager.sortAnnotationsByPosition(groupedAnnotationsByPageMap); - let flattenedAnnotationsByPosition = pdfAnnotationsManager.flattenAnnotationsByPosition(sortedAnnotationsByPositionGroupedByPage); - - const finalMarkdown = this.generateFinalMarkdown(flattenedAnnotationsByPosition, file.name); - - let filePath = file.name.replace(".pdf", ".md"); - filePath = "Highlights for " + filePath; - - await this.saveHighlightsToFile(filePath, finalMarkdown); - await this.app.workspace.openLinkText(filePath, '', true); + this.modal = new ProgressModal(this.app); + this.modal.open(); + + // let file = this.app.workspace.getActiveFile(); + // + // if (file === null) return; + // if (file.extension !== 'pdf') return; + // + // let arrayBuffer = await this.app.vault.readBinary(file); + // let pdfAnnotationsManager = new PDFAnnotationsManager(); + // + // let rawAnnotationsFromPDF = await pdfAnnotationsManager.fetchRawAnnotationsFromPDF(arrayBuffer); + // let filteredAnnotations = pdfAnnotationsManager.filterRawAnnotations(rawAnnotationsFromPDF); + // let groupedAnnotationsByPageMap = pdfAnnotationsManager.groupAnnotationsByPage(filteredAnnotations); + // let sortedAnnotationsByPositionGroupedByPage = pdfAnnotationsManager.sortAnnotationsByPosition(groupedAnnotationsByPageMap); + // let flattenedAnnotationsByPosition = pdfAnnotationsManager.flattenAnnotationsByPosition(sortedAnnotationsByPositionGroupedByPage); + // + // const finalMarkdown = this.generateFinalMarkdown(flattenedAnnotationsByPosition, file.name); + // + // let filePath = file.name.replace(".pdf", ".md"); + // filePath = "Highlights for " + filePath; + // + // await this.saveHighlightsToFile(filePath, finalMarkdown); + // await this.app.workspace.openLinkText(filePath, '', true); } private generateFinalMarkdown(annotations, fileName) { @@ -135,3 +139,22 @@ export default class ExtractPDFHighlightsPlugin extends Plugin { return ""; } } + +class ProgressModal extends Modal { + public fileName: string; + + constructor(app: App) { + super(app); + } + + onOpen() { + let {contentEl} = this; + contentEl.createEl("h2", {text: "Extract PDF Highlights"}); + contentEl.createEl("p", {text: "I'm sorry but due to an unexpected incompatibility with Obsidian Core PDF handling as of v0.10.8 this plugin is currently disabled. In the meantime, you can use Zotero + Zotfile to extract PDF highlights and annotations. I'm sorry for the inconvenience and working on fixing this issue. If you have any questions, please email me at alexis.rondeau@gmail.com! Thank you for your patience, Alexis :)"}); + } + + onClose() { + let {contentEl} = this; + contentEl.empty(); + } +}