mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 01:16:15 +02:00
chore(print/pdf): make use of attribute for adjusting orientation
This commit is contained in:
@@ -147,9 +147,11 @@ export default function NoteDetail() {
|
||||
toast.closePersistent("printing");
|
||||
handlePrintReport(printReport);
|
||||
};
|
||||
const onPreviewResult = (_e: any, { buffer, title, notePath, pageSize, landscape }: { buffer: Uint8Array; title: string; notePath: string; pageSize: string; landscape: boolean }) => {
|
||||
const onPreviewResult = (_e: any, { buffer, notePath, pageSize }: { buffer: Uint8Array; notePath: string; pageSize: string }) => {
|
||||
toast.closePersistent("printing");
|
||||
appContext.triggerCommand("showPrintPreview", { pdfBuffer: buffer, title, notePath, pageSize, landscape });
|
||||
if (note) {
|
||||
appContext.triggerCommand("showPrintPreview", { pdfBuffer: buffer, note, notePath, pageSize });
|
||||
}
|
||||
};
|
||||
ipcRenderer.on("print-progress", onPrintProgress);
|
||||
ipcRenderer.on("print-done", onPrintDone);
|
||||
@@ -159,7 +161,7 @@ export default function NoteDetail() {
|
||||
ipcRenderer.off("print-done", onPrintDone);
|
||||
ipcRenderer.off("export-as-pdf-preview-result", onPreviewResult);
|
||||
};
|
||||
}, []);
|
||||
}, [note]);
|
||||
|
||||
useTriliumEvent("executeInActiveNoteDetailWidget", ({ callback }) => {
|
||||
if (!noteContext?.isActive()) return;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useCallback, useRef, useState } from "preact/hooks";
|
||||
|
||||
import FNote from "../../entities/fnote";
|
||||
import { t } from "../../services/i18n";
|
||||
import toast from "../../services/toast";
|
||||
import { dynamicRequire, isElectron } from "../../services/utils";
|
||||
import Button, { ButtonGroup } from "../react/Button";
|
||||
import { useTriliumEvent } from "../react/hooks";
|
||||
import { useNoteLabelBoolean, useTriliumEvent } from "../react/hooks";
|
||||
import Modal from "../react/Modal";
|
||||
import PdfViewer from "../type_widgets/file/PdfViewer";
|
||||
import OptionsRow from "../type_widgets/options/components/OptionsRow";
|
||||
@@ -12,22 +13,22 @@ import OptionsSection from "../type_widgets/options/components/OptionsSection";
|
||||
|
||||
export interface PrintPreviewData {
|
||||
pdfBuffer: Uint8Array;
|
||||
title: string;
|
||||
note: FNote;
|
||||
notePath: string;
|
||||
pageSize: string;
|
||||
landscape: boolean;
|
||||
}
|
||||
|
||||
export default function PrintPreviewDialog() {
|
||||
const [shown, setShown] = useState(false);
|
||||
const [pdfUrl, setPdfUrl] = useState<string>();
|
||||
const [landscape, setLandscape] = useState(false);
|
||||
const [note, setNote] = useState<FNote>();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const bufferRef = useRef<Uint8Array>();
|
||||
const titleRef = useRef("");
|
||||
const notePathRef = useRef("");
|
||||
const pageSizeRef = useRef("");
|
||||
|
||||
const [landscape, setLandscape] = useNoteLabelBoolean(note, "printLandscape");
|
||||
|
||||
const updatePreview = useCallback((buffer: Uint8Array) => {
|
||||
bufferRef.current = buffer;
|
||||
|
||||
@@ -42,10 +43,9 @@ export default function PrintPreviewDialog() {
|
||||
}, [pdfUrl]);
|
||||
|
||||
useTriliumEvent("showPrintPreview", (data: PrintPreviewData) => {
|
||||
titleRef.current = data.title;
|
||||
setNote(data.note);
|
||||
notePathRef.current = data.notePath;
|
||||
pageSizeRef.current = data.pageSize;
|
||||
setLandscape(data.landscape);
|
||||
updatePreview(data.pdfBuffer);
|
||||
setShown(true);
|
||||
});
|
||||
@@ -65,7 +65,7 @@ export default function PrintPreviewDialog() {
|
||||
|
||||
const { ipcRenderer } = dynamicRequire("electron");
|
||||
ipcRenderer.send("save-pdf", {
|
||||
title: titleRef.current,
|
||||
title: note?.title ?? "",
|
||||
buffer: bufferRef.current
|
||||
});
|
||||
handleClose();
|
||||
@@ -91,7 +91,7 @@ export default function PrintPreviewDialog() {
|
||||
ipcRenderer.once("export-as-pdf-preview-result", onResult);
|
||||
|
||||
ipcRenderer.send("export-as-pdf-preview", {
|
||||
title: titleRef.current,
|
||||
title: note?.title ?? "",
|
||||
notePath: notePathRef.current,
|
||||
pageSize: pageSizeRef.current,
|
||||
landscape: newLandscape
|
||||
|
||||
@@ -168,7 +168,7 @@ electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pag
|
||||
}
|
||||
});
|
||||
|
||||
electron.ipcMain.on("export-as-pdf-preview", async (e, { title, notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
||||
electron.ipcMain.on("export-as-pdf-preview", async (e, { notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
||||
try {
|
||||
const { browserWindow, printReport } = await getBrowserWindowForPrinting(e, notePath, "exporting_pdf");
|
||||
|
||||
@@ -187,7 +187,7 @@ electron.ipcMain.on("export-as-pdf-preview", async (e, { title, notePath, landsc
|
||||
`
|
||||
});
|
||||
|
||||
e.sender.send("export-as-pdf-preview-result", { buffer, title, notePath, pageSize, landscape });
|
||||
e.sender.send("export-as-pdf-preview-result", { buffer, notePath, pageSize });
|
||||
} catch (_e) {
|
||||
electron.dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-export-message"));
|
||||
} finally {
|
||||
|
||||
@@ -60,6 +60,9 @@ type Labels = {
|
||||
"presentation:theme": string;
|
||||
"slide:background": string;
|
||||
|
||||
// Print/export
|
||||
printLandscape: boolean;
|
||||
|
||||
// Note-type specific
|
||||
webViewSrc: string;
|
||||
"disabled:webViewSrc": string;
|
||||
|
||||
Reference in New Issue
Block a user