mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 02:24:23 +01:00
feat(print): report progress on export to PDF as well
This commit is contained in:
parent
1a6e653600
commit
6023d53506
@ -113,10 +113,7 @@ export default function NoteDetail() {
|
||||
useEffect(() => {
|
||||
if (!isElectron()) return;
|
||||
const { ipcRenderer } = dynamicRequire("electron");
|
||||
const onPrintProgress = (_e: any, progress: number) => {
|
||||
console.log("Got print progress:", progress);
|
||||
showToast("printing", progress);
|
||||
};
|
||||
const onPrintProgress = (_e: any, { progress, action }: { progress: number, action: "printing" | "exporting_pdf" }) => showToast(action, progress);
|
||||
const onPrintDone = () => toast.closePersistent("printing");
|
||||
ipcRenderer.on("print-progress", onPrintProgress);
|
||||
ipcRenderer.on("print-done", onPrintDone);
|
||||
@ -179,11 +176,7 @@ export default function NoteDetail() {
|
||||
|
||||
useTriliumEvent("exportAsPdf", () => {
|
||||
if (!noteContext?.isActive() || !note) return;
|
||||
toast.showPersistent({
|
||||
icon: "bx bx-loader-circle bx-spin",
|
||||
message: t("note_detail.printing_pdf"),
|
||||
id: "printing"
|
||||
});
|
||||
showToast("exporting_pdf");
|
||||
|
||||
const { ipcRenderer } = dynamicRequire("electron");
|
||||
ipcRenderer.send("export-as-pdf", {
|
||||
@ -332,7 +325,7 @@ function checkFullHeight(noteContext: NoteContext | undefined, type: ExtendedNot
|
||||
function showToast(type: "printing" | "exporting_pdf", progress: number = 0) {
|
||||
toast.showPersistent({
|
||||
icon: "bx bx-loader-circle bx-spin",
|
||||
message: t("note_detail.printing"),
|
||||
message: type === "printing" ? t("note_detail.printing") : t("note_detail.printing_pdf"),
|
||||
id: "printing",
|
||||
progress
|
||||
});
|
||||
|
||||
@ -80,7 +80,7 @@ interface ExportAsPdfOpts {
|
||||
}
|
||||
|
||||
electron.ipcMain.on("print-note", async (e, { notePath }: PrintOpts) => {
|
||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath, "printing");
|
||||
browserWindow.webContents.print({}, (success, failureReason) => {
|
||||
if (!success) {
|
||||
electron.dialog.showErrorBox(t("pdf.unable-to-print"), failureReason);
|
||||
@ -91,7 +91,7 @@ electron.ipcMain.on("print-note", async (e, { notePath }: PrintOpts) => {
|
||||
});
|
||||
|
||||
electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath, "exporting_pdf");
|
||||
|
||||
async function print() {
|
||||
const filePath = electron.dialog.showSaveDialogSync(browserWindow, {
|
||||
@ -143,7 +143,7 @@ electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pag
|
||||
}
|
||||
});
|
||||
|
||||
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
||||
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string, action: "printing" | "exporting_pdf") {
|
||||
const browserWindow = new electron.BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
@ -154,7 +154,7 @@ async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
||||
},
|
||||
});
|
||||
|
||||
const progressCallback = (_e, progress: number) => e.sender.send("print-progress", progress);
|
||||
const progressCallback = (_e, progress: number) => e.sender.send("print-progress", { progress, action });
|
||||
ipcMain.on("print-progress", progressCallback);
|
||||
|
||||
await browserWindow.loadURL(`http://127.0.0.1:${port}/?print#${notePath}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user