mirror of
https://github.com/zadam/trilium.git
synced 2026-01-10 16:44:29 +01:00
feat(client/pdf): add debouncing
This commit is contained in:
parent
c0a90402ef
commit
3e255fa647
@ -9,15 +9,26 @@ async function main() {
|
|||||||
|
|
||||||
app.eventBus.on("documentloaded", () => {
|
app.eventBus.on("documentloaded", () => {
|
||||||
const storage = app.pdfDocument.annotationStorage;
|
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 () => {
|
storage.onSetModified = async () => {
|
||||||
console.log("Document modified");
|
debouncedSave();
|
||||||
const data = await app.pdfDocument.saveDocument();
|
|
||||||
window.parent.postMessage({
|
|
||||||
type: "pdfjs-viewer-document-modified",
|
|
||||||
data: data
|
|
||||||
}, "*");
|
|
||||||
storage.resetModified();
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user