diff --git a/app/pnpm-lock.yaml b/app/pnpm-lock.yaml index eed988a4f..cd45f4b2a 100644 --- a/app/pnpm-lock.yaml +++ b/app/pnpm-lock.yaml @@ -1906,10 +1906,10 @@ packages: resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==} engines: {node: '>=14.0.0'} dependencies: - 7zip-bin: 5.1.1 '@develar/schema-utils': 2.6.5 '@electron/universal': 1.2.1 '@malept/flatpak-bundler': 0.4.0 + 7zip-bin: 5.1.1 async-exit-hook: 2.0.1 bluebird-lst: 1.0.9 builder-util: 23.3.3 @@ -2193,9 +2193,9 @@ packages: /builder-util/23.3.3: resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==} dependencies: - 7zip-bin: 5.1.1 '@types/debug': 4.1.7 '@types/fs-extra': 9.0.13 + 7zip-bin: 5.1.1 app-builder-bin: 4.0.0 bluebird-lst: 1.0.9 builder-util-runtime: 9.0.3 diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 31661e3b7..aa243cd61 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -1,7 +1,7 @@ import {hideMessage, showMessage} from "../../dialog/message"; import {Constants} from "../../constants"; /// #if !BROWSER -import {ipcRenderer, OpenDialogReturnValue} from "electron"; +import {OpenDialogReturnValue} from "electron"; import {BrowserWindow, dialog} from "@electron/remote"; import * as fs from "fs"; import * as path from "path"; @@ -61,10 +61,6 @@ export const saveExport = (option: { type: string, id: string }) => { }; /// #if !BROWSER -const destroyWin = (win: Electron.BrowserWindow) => { - win.destroy(); -}; - const renderPDF = (id: string) => { const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({ printBackground: true, @@ -75,7 +71,7 @@ const renderPDF = (id: string) => { removeAssets: true, })); const servePath = window.location.protocol + "//" + window.location.host; - const win = new BrowserWindow({ + window.siyuan.printWin = new BrowserWindow({ show: true, width: 1032, resizable: false, @@ -89,74 +85,6 @@ const renderPDF = (id: string) => { webSecurity: false, }, }); - ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => { - win.destroy(); - }); - ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => { - dialog.showOpenDialog({ - title: window.siyuan.languages.export + " PDF", - properties: ["createDirectory", "openDirectory"], - }).then((result: OpenDialogReturnValue) => { - if (result.canceled) { - destroyWin(win); - return; - } - - setTimeout(() => { - const msgId = showMessage(window.siyuan.languages.exporting, -1); - const filePath = result.filePaths[0].endsWith(ipcData.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle)); - localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, {removeAssets: ipcData.removeAssets}))); - try { - win.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => { - fetchPost("/api/export/exportHTML", { - id: ipcData.rootId, - pdf: true, - removeAssets: ipcData.removeAssets, - savePath: filePath - }, () => { - const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf"); - fs.writeFileSync(pdfFilePath, pdfData); - destroyWin(win); - fetchPost("/api/export/addPDFOutline", { - id: ipcData.rootId, - path: pdfFilePath - }, () => { - afterExport(pdfFilePath, msgId); - if (ipcData.removeAssets) { - const removePromise = (dir: string) => { - return new Promise(function (resolve) { - //先读文件夹 - fs.stat(dir, function (err, stat) { - if (stat) { - if (stat.isDirectory()) { - fs.readdir(dir, function (err, files) { - files = files.map(file => path.join(dir, file)); // a/b a/m - Promise.all(files.map(file => removePromise(file))).then(function () { - fs.rmdir(dir, resolve); - }); - }); - } else { - fs.unlink(dir, resolve); - } - } - }); - }); - }; - removePromise(path.join(filePath, "assets")); - } - }); - }); - }).catch((error: string) => { - showMessage("Export PDF error:" + error, 0, "error", msgId); - destroyWin(win); - }); - } catch (e) { - showMessage("Export PDF failed: " + e, 0, "error", msgId); - destroyWin(win); - } - }, 200); - }); - }); let pdfWidth = ""; if (localData.pageSize === "A3") { if (localData.landscape) { @@ -218,50 +146,57 @@ const renderPDF = (id: string) => {