mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix: use toast for Save as PDF
- DRY for export toast
This commit is contained in:
parent
8e62272d08
commit
81c6812e2f
@ -1,10 +1,5 @@
|
||||
import frappe from 'frappejs';
|
||||
import {
|
||||
getSavePath,
|
||||
saveData,
|
||||
showItemInFolder,
|
||||
showToast,
|
||||
} from '../src/utils';
|
||||
import { getSavePath, saveData, showExportInFolder } from '../src/utils';
|
||||
|
||||
function templateToInnerText(innerHTML) {
|
||||
const temp = document.createElement('template');
|
||||
@ -106,11 +101,5 @@ export default function getCommonExportActions(reportName) {
|
||||
|
||||
export async function saveExportData(data, filePath) {
|
||||
await saveData(data, filePath);
|
||||
showToast({
|
||||
message: frappe._('Export Successful'),
|
||||
actionText: frappe._('Open Folder'),
|
||||
action: async () => {
|
||||
await showItemInFolder(filePath);
|
||||
},
|
||||
});
|
||||
showExportInFolder(frappe._('Export Successful'), filePath);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import fs from 'fs';
|
||||
import { sleep } from 'frappejs/utils';
|
||||
import { shell, BrowserWindow } from 'electron';
|
||||
import { BrowserWindow } from 'electron';
|
||||
import fs from 'fs/promises';
|
||||
|
||||
const PRINT_OPTIONS = {
|
||||
marginsType: 1, // no margin
|
||||
@ -17,14 +16,16 @@ export default async function makePDF(html, savePath) {
|
||||
document.body.innerHTML = \`${html}\`;
|
||||
`);
|
||||
|
||||
printWindow.webContents.on('did-finish-load', async () => {
|
||||
await sleep(1); // Required else pdf'll be blank.
|
||||
printWindow.webContents.printToPDF(PRINT_OPTIONS).then((data) => {
|
||||
// printWindow.destroy();
|
||||
fs.writeFile(savePath, data, (error) => {
|
||||
return await new Promise((resolve) => {
|
||||
printWindow.webContents.on('did-finish-load', async () => {
|
||||
await sleep(1); // Required else pdf'll be blank.
|
||||
|
||||
const data = await printWindow.webContents.printToPDF(PRINT_OPTIONS);
|
||||
await fs.writeFile(savePath, data, (error) => {
|
||||
if (error) throw error;
|
||||
return shell.openPath(savePath);
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
11
src/utils.js
11
src/utils.js
@ -174,6 +174,17 @@ export function handleErrorWithDialog(e, doc) {
|
||||
|
||||
export async function makePDF(html, savePath) {
|
||||
await ipcRenderer.invoke(IPC_ACTIONS.SAVE_HTML_AS_PDF, html, savePath);
|
||||
showExportInFolder(frappe._('Save as PDF Successful'), savePath);
|
||||
}
|
||||
|
||||
export function showExportInFolder(message, filePath) {
|
||||
showToast({
|
||||
message,
|
||||
actionText: frappe._('Open Folder'),
|
||||
action: async () => {
|
||||
await showItemInFolder(filePath);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveData(data, savePath) {
|
||||
|
Loading…
Reference in New Issue
Block a user