This commit is contained in:
parent
65921ad6d7
commit
1abb0843b5
3 changed files with 15 additions and 8 deletions
|
@ -61,6 +61,7 @@ export const saveExport = (option: { type: string, id: string }) => {
|
|||
};
|
||||
|
||||
/// #if !BROWSER
|
||||
let originalZoomFactor = 1;
|
||||
const renderPDF = (id: string) => {
|
||||
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({
|
||||
landscape: false,
|
||||
|
@ -371,12 +372,13 @@ const renderPDF = (id: string) => {
|
|||
});
|
||||
</script></body></html>`;
|
||||
const mainWindow = getCurrentWindow();
|
||||
const mainWindowZoomFactor = mainWindow.webContents.getZoomFactor();
|
||||
originalZoomFactor = mainWindow.webContents.zoomFactor;
|
||||
window.siyuan.printWin = new BrowserWindow({
|
||||
parent: mainWindow,
|
||||
modal: true,
|
||||
show: true,
|
||||
width: 1032,
|
||||
height: 618,
|
||||
resizable: false,
|
||||
frame: "darwin" === window.siyuan.config.system.os,
|
||||
icon: path.join(window.siyuan.config.system.appDir, "stage", "icon-large.png"),
|
||||
|
@ -393,12 +395,16 @@ const renderPDF = (id: string) => {
|
|||
// 导出 PDF 预览界面不受主界面缩放影响 https://github.com/siyuan-note/siyuan/issues/6262
|
||||
window.siyuan.printWin.webContents.setZoomFactor(1);
|
||||
});
|
||||
window.siyuan
|
||||
fetchPost("/api/export/exportTempContent", {content: html}, (response) => {
|
||||
window.siyuan.printWin.loadURL(response.data.url);
|
||||
});
|
||||
};
|
||||
|
||||
export const destroyPrintWindow = () => {
|
||||
getCurrentWindow().webContents.setZoomFactor(originalZoomFactor);
|
||||
window.siyuan.printWin.destroy();
|
||||
};
|
||||
|
||||
const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean) => {
|
||||
fetchPost("/api/block/getBlockInfo", {
|
||||
id: option.id
|
||||
|
|
|
@ -96,7 +96,7 @@ export const getTopEmptyElement = (element: Element) => {
|
|||
if (!topElement.parentElement.getAttribute("data-node-id")) {
|
||||
topElement = topElement.parentElement;
|
||||
} else {
|
||||
let hasText = false
|
||||
let hasText = false;
|
||||
Array.from(topElement.parentElement.querySelectorAll('[contenteditable="true"]')).find(item => {
|
||||
if (item.textContent.replace(Constants.ZWSP, "").replace("\n", "") !== "") {
|
||||
hasText = true;
|
||||
|
|
|
@ -28,6 +28,7 @@ import {showMessage} from "../dialog/message";
|
|||
import {replaceLocalPath} from "../editor/rename";
|
||||
import {editor} from "../config/editor";
|
||||
import {goBack, goForward} from "./backForward";
|
||||
import {destroyPrintWindow} from "../protyle/export";
|
||||
|
||||
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
||||
if (key1 === "general") {
|
||||
|
@ -381,7 +382,7 @@ const initWindow = () => {
|
|||
winOnClose(currentWindow, close);
|
||||
});
|
||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
||||
window.siyuan.printWin.destroy();
|
||||
destroyPrintWindow();
|
||||
});
|
||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
||||
dialog.showOpenDialog({
|
||||
|
@ -389,7 +390,7 @@ const initWindow = () => {
|
|||
properties: ["createDirectory", "openDirectory"],
|
||||
}).then((result: OpenDialogReturnValue) => {
|
||||
if (result.canceled) {
|
||||
window.siyuan.printWin.destroy();
|
||||
destroyPrintWindow();
|
||||
return;
|
||||
}
|
||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||
|
@ -405,7 +406,7 @@ const initWindow = () => {
|
|||
}, () => {
|
||||
const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf");
|
||||
fs.writeFileSync(pdfFilePath, pdfData);
|
||||
window.siyuan.printWin.destroy();
|
||||
destroyPrintWindow();
|
||||
fetchPost("/api/export/addPDFOutline", {
|
||||
id: ipcData.rootId,
|
||||
path: pdfFilePath
|
||||
|
@ -437,11 +438,11 @@ const initWindow = () => {
|
|||
});
|
||||
}).catch((error: string) => {
|
||||
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
||||
window.siyuan.printWin.destroy();
|
||||
destroyPrintWindow();
|
||||
});
|
||||
} catch (e) {
|
||||
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
||||
window.siyuan.printWin.destroy();
|
||||
destroyPrintWindow();
|
||||
}
|
||||
window.siyuan.printWin.hide();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue