mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 09:56:36 +01:00
chore(client/print): address requested changes
This commit is contained in:
@@ -26,6 +26,7 @@ function App({ note, noteId }: { note: FNote | null | undefined, noteId: string
|
|||||||
const onReady = useCallback(() => {
|
const onReady = useCallback(() => {
|
||||||
if (sentReadyEvent.current) return;
|
if (sentReadyEvent.current) return;
|
||||||
window.dispatchEvent(new Event("note-ready"));
|
window.dispatchEvent(new Event("note-ready"));
|
||||||
|
window._noteReady = true;
|
||||||
sentReadyEvent.current = true;
|
sentReadyEvent.current = true;
|
||||||
}, []);
|
}, []);
|
||||||
const props: RendererProps | undefined | null = note && { note, onReady };
|
const props: RendererProps | undefined | null = note && { note, onReady };
|
||||||
|
|||||||
3
apps/client/src/types.d.ts
vendored
3
apps/client/src/types.d.ts
vendored
@@ -59,6 +59,9 @@ declare global {
|
|||||||
process?: ElectronProcess;
|
process?: ElectronProcess;
|
||||||
glob?: CustomGlobals;
|
glob?: CustomGlobals;
|
||||||
|
|
||||||
|
/** On the printing endpoint, set to true when the note has fully loaded and is ready to be printed/exported as PDF. */
|
||||||
|
_noteReady?: boolean;
|
||||||
|
|
||||||
EXCALIDRAW_ASSET_PATH?: string;
|
EXCALIDRAW_ASSET_PATH?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -322,7 +322,12 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
iframe.className = "print-iframe";
|
iframe.className = "print-iframe";
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
if (!iframe.contentWindow) return;
|
if (!iframe.contentWindow) {
|
||||||
|
toast.closePersistent("printing");
|
||||||
|
document.body.removeChild(iframe);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
iframe.contentWindow.addEventListener("note-ready", () => {
|
iframe.contentWindow.addEventListener("note-ready", () => {
|
||||||
toast.closePersistent("printing");
|
toast.closePersistent("printing");
|
||||||
iframe.contentWindow?.print();
|
iframe.contentWindow?.print();
|
||||||
|
|||||||
@@ -84,19 +84,18 @@ interface ExportAsPdfOpts {
|
|||||||
electron.ipcMain.on("print-note", async (e, { notePath }: PrintOpts) => {
|
electron.ipcMain.on("print-note", async (e, { notePath }: PrintOpts) => {
|
||||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
||||||
browserWindow.webContents.print({}, (success, failureReason) => {
|
browserWindow.webContents.print({}, (success, failureReason) => {
|
||||||
if (success) {
|
if (!success) {
|
||||||
browserWindow.destroy();
|
|
||||||
} else {
|
|
||||||
electron.dialog.showErrorBox(t("pdf.unable-to-print"), failureReason);
|
electron.dialog.showErrorBox(t("pdf.unable-to-print"), failureReason);
|
||||||
}
|
}
|
||||||
e.sender.send("print-done");
|
e.sender.send("print-done");
|
||||||
|
browserWindow.destroy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
||||||
async function print() {
|
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
||||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
|
||||||
|
|
||||||
|
async function print() {
|
||||||
const filePath = electron.dialog.showSaveDialogSync(browserWindow, {
|
const filePath = electron.dialog.showSaveDialogSync(browserWindow, {
|
||||||
defaultPath: formatDownloadTitle(title, "file", "application/pdf"),
|
defaultPath: formatDownloadTitle(title, "file", "application/pdf"),
|
||||||
filters: [
|
filters: [
|
||||||
@@ -138,8 +137,12 @@ electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pag
|
|||||||
electron.shell.openPath(filePath);
|
electron.shell.openPath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
await print();
|
try {
|
||||||
e.sender.send("print-done");
|
await print();
|
||||||
|
} finally {
|
||||||
|
e.sender.send("print-done");
|
||||||
|
browserWindow.destroy();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user