mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 03:46:37 +01:00
fix(desktop/print): proper reporting when it finishes
This commit is contained in:
@@ -1723,7 +1723,8 @@
|
||||
},
|
||||
"note_detail": {
|
||||
"could_not_find_typewidget": "Could not find typeWidget for type '{{type}}'",
|
||||
"printing": "Printing in progress..."
|
||||
"printing": "Printing in progress...",
|
||||
"printing_pdf": "Exporting to PDF in progress..."
|
||||
},
|
||||
"note_title": {
|
||||
"placeholder": "type note's title here..."
|
||||
|
||||
@@ -141,6 +141,13 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.contentSized();
|
||||
|
||||
if (utils.isElectron()) {
|
||||
const { ipcRenderer } = utils.dynamicRequire("electron");
|
||||
ipcRenderer.on("print-done", () => {
|
||||
toast.closePersistent("printing");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
@@ -330,6 +337,12 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
toast.showPersistent({
|
||||
icon: "bx bx-loader-circle bx-spin",
|
||||
message: t("note_detail.printing_pdf"),
|
||||
id: "printing"
|
||||
});
|
||||
|
||||
const { ipcRenderer } = utils.dynamicRequire("electron");
|
||||
ipcRenderer.send("export-as-pdf", {
|
||||
title: this.note.title,
|
||||
|
||||
@@ -89,30 +89,12 @@ electron.ipcMain.on("print-note", async (e, { notePath }: PrintOpts) => {
|
||||
} else {
|
||||
electron.dialog.showErrorBox(t("pdf.unable-to-print"), failureReason);
|
||||
}
|
||||
e.sender.send("print-done");
|
||||
});
|
||||
});
|
||||
|
||||
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
||||
const browserWindow = new electron.BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
offscreen: true,
|
||||
session: e.sender.session
|
||||
},
|
||||
});
|
||||
await browserWindow.loadURL(`http://127.0.0.1:${port}/?print#${notePath}`);
|
||||
await browserWindow.webContents.executeJavaScript(`
|
||||
new Promise(resolve => {
|
||||
if (window._noteReady) return resolve();
|
||||
window.addEventListener("note-ready", () => resolve());
|
||||
});
|
||||
`);
|
||||
return browserWindow;
|
||||
}
|
||||
|
||||
electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pageSize }: ExportAsPdfOpts) => {
|
||||
async function print() {
|
||||
const browserWindow = await getBrowserWindowForPrinting(e, notePath);
|
||||
|
||||
const filePath = electron.dialog.showSaveDialogSync(browserWindow, {
|
||||
@@ -124,9 +106,7 @@ electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pag
|
||||
}
|
||||
]
|
||||
});
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
if (!filePath) return;
|
||||
|
||||
let buffer: Buffer;
|
||||
try {
|
||||
@@ -156,8 +136,32 @@ electron.ipcMain.on("export-as-pdf", async (e, { title, notePath, landscape, pag
|
||||
}
|
||||
|
||||
electron.shell.openPath(filePath);
|
||||
}
|
||||
|
||||
await print();
|
||||
e.sender.send("print-done");
|
||||
});
|
||||
|
||||
async function getBrowserWindowForPrinting(e: IpcMainEvent, notePath: string) {
|
||||
const browserWindow = new electron.BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
offscreen: true,
|
||||
session: e.sender.session
|
||||
},
|
||||
});
|
||||
await browserWindow.loadURL(`http://127.0.0.1:${port}/?print#${notePath}`);
|
||||
await browserWindow.webContents.executeJavaScript(`
|
||||
new Promise(resolve => {
|
||||
if (window._noteReady) return resolve();
|
||||
window.addEventListener("note-ready", () => resolve());
|
||||
});
|
||||
`);
|
||||
return browserWindow;
|
||||
}
|
||||
|
||||
async function createMainWindow(app: App) {
|
||||
if ("setUserTasks" in app) {
|
||||
app.setUserTasks([
|
||||
|
||||
Reference in New Issue
Block a user