mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 18:54:29 +01:00
feat(client/pdf): add debouncing
This commit is contained in:
parent
c0a90402ef
commit
3e255fa647
@ -5,19 +5,30 @@ async function main() {
|
||||
}
|
||||
|
||||
const app = PDFViewerApplication;
|
||||
await app.initializedPromise;
|
||||
|
||||
await app.initializedPromise;
|
||||
|
||||
app.eventBus.on("documentloaded", () => {
|
||||
const storage = app.pdfDocument.annotationStorage;
|
||||
let timeout = null;
|
||||
|
||||
function debouncedSave() {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
timeout = setTimeout(async () => {
|
||||
console.log("Triggered debounce save");
|
||||
const data = await app.pdfDocument.saveDocument();
|
||||
window.parent.postMessage({
|
||||
type: "pdfjs-viewer-document-modified",
|
||||
data: data
|
||||
}, "*");
|
||||
storage.resetModified();
|
||||
timeout = null;
|
||||
}, 2_000);
|
||||
}
|
||||
|
||||
storage.onSetModified = async () => {
|
||||
console.log("Document modified");
|
||||
const data = await app.pdfDocument.saveDocument();
|
||||
window.parent.postMessage({
|
||||
type: "pdfjs-viewer-document-modified",
|
||||
data: data
|
||||
}, "*");
|
||||
storage.resetModified();
|
||||
debouncedSave();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user