diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx index 406354eee..5b5838584 100644 --- a/apps/client/src/widgets/NoteDetail.tsx +++ b/apps/client/src/widgets/NoteDetail.tsx @@ -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 }); diff --git a/apps/server/src/services/window.ts b/apps/server/src/services/window.ts index 8f2d26f47..626ab851f 100644 --- a/apps/server/src/services/window.ts +++ b/apps/server/src/services/window.ts @@ -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}`);