mirror of
https://github.com/zadam/trilium.git
synced 2025-12-30 19:24:24 +01:00
This commit is contained in:
parent
07a1734d4b
commit
0a9ce84cf2
@ -5,6 +5,7 @@ import FBlob from "../../../entities/fblob";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import server from "../../../services/server";
|
||||
import { useViewModeConfig } from "../../collections/NoteList";
|
||||
import { useTriliumOption } from "../../react/hooks";
|
||||
|
||||
const VARIABLE_WHITELIST = new Set([
|
||||
"root-background",
|
||||
@ -21,6 +22,7 @@ export default function PdfPreview({ note, blob, componentId }: {
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const { onLoad } = useStyleInjection(iframeRef);
|
||||
const historyConfig = useViewModeConfig(note, "pdfHistory");
|
||||
const [ locale ] = useTriliumOption("locale");
|
||||
|
||||
useEffect(() => {
|
||||
function handleMessage(event: MessageEvent) {
|
||||
@ -51,10 +53,11 @@ export default function PdfPreview({ note, blob, componentId }: {
|
||||
<iframe
|
||||
ref={iframeRef}
|
||||
class="pdf-preview"
|
||||
src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open`}
|
||||
src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open&lang=${locale}`}
|
||||
onLoad={() => {
|
||||
if (iframeRef.current?.contentWindow) {
|
||||
iframeRef.current.contentWindow.TRILIUM_VIEW_HISTORY_STORE = historyConfig.config;
|
||||
const win = iframeRef.current?.contentWindow;
|
||||
if (win) {
|
||||
win.TRILIUM_VIEW_HISTORY_STORE = historyConfig.config;
|
||||
}
|
||||
onLoad();
|
||||
}}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import interceptViewHistory from "./history";
|
||||
import interceptPersistence from "./persistence";
|
||||
|
||||
const LOG_EVENT_BUS = false;
|
||||
|
||||
async function main() {
|
||||
interceptPersistence(getCustomAppOptions());
|
||||
|
||||
// Wait for the PDF viewer application to be available.
|
||||
while (!window.PDFViewerApplication) {
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
}
|
||||
|
||||
const app = window.PDFViewerApplication;
|
||||
interceptViewHistory();
|
||||
|
||||
if (LOG_EVENT_BUS) {
|
||||
patchEventBus();
|
||||
@ -20,6 +20,17 @@ async function main() {
|
||||
await app.initializedPromise;
|
||||
};
|
||||
|
||||
function getCustomAppOptions() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
return {
|
||||
localeProperties: {
|
||||
// Read from URL query
|
||||
lang: urlParams.get("lang") || "en"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function manageSave() {
|
||||
const app = window.PDFViewerApplication;
|
||||
const storage = app.pdfDocument.annotationStorage;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export default function interceptViewHistory() {
|
||||
export default function interceptViewHistory(customOptions?: object) {
|
||||
const originalSetItem = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function (key: string, value: string) {
|
||||
if (key === "pdfjs.history") {
|
||||
@ -11,6 +11,10 @@ export default function interceptViewHistory() {
|
||||
|
||||
const originalGetItem = Storage.prototype.getItem;
|
||||
Storage.prototype.getItem = function (key: string) {
|
||||
if (key === "pdfjs.preferences") {
|
||||
return JSON.stringify(customOptions);
|
||||
}
|
||||
|
||||
if (key === "pdfjs.history") {
|
||||
return JSON.stringify(window.TRILIUM_VIEW_HISTORY_STORE || {});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user