This commit is contained in:
Vanessa 2022-10-25 14:43:03 +08:00
parent 65921ad6d7
commit 1abb0843b5
3 changed files with 15 additions and 8 deletions

View file

@ -61,6 +61,7 @@ export const saveExport = (option: { type: string, id: string }) => {
}; };
/// #if !BROWSER /// #if !BROWSER
let originalZoomFactor = 1;
const renderPDF = (id: string) => { const renderPDF = (id: string) => {
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({ const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({
landscape: false, landscape: false,
@ -371,12 +372,13 @@ const renderPDF = (id: string) => {
}); });
</script></body></html>`; </script></body></html>`;
const mainWindow = getCurrentWindow(); const mainWindow = getCurrentWindow();
const mainWindowZoomFactor = mainWindow.webContents.getZoomFactor(); originalZoomFactor = mainWindow.webContents.zoomFactor;
window.siyuan.printWin = new BrowserWindow({ window.siyuan.printWin = new BrowserWindow({
parent: mainWindow, parent: mainWindow,
modal: true, modal: true,
show: true, show: true,
width: 1032, width: 1032,
height: 618,
resizable: false, resizable: false,
frame: "darwin" === window.siyuan.config.system.os, frame: "darwin" === window.siyuan.config.system.os,
icon: path.join(window.siyuan.config.system.appDir, "stage", "icon-large.png"), 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 // 导出 PDF 预览界面不受主界面缩放影响 https://github.com/siyuan-note/siyuan/issues/6262
window.siyuan.printWin.webContents.setZoomFactor(1); window.siyuan.printWin.webContents.setZoomFactor(1);
}); });
window.siyuan
fetchPost("/api/export/exportTempContent", {content: html}, (response) => { fetchPost("/api/export/exportTempContent", {content: html}, (response) => {
window.siyuan.printWin.loadURL(response.data.url); 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) => { const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean) => {
fetchPost("/api/block/getBlockInfo", { fetchPost("/api/block/getBlockInfo", {
id: option.id id: option.id

View file

@ -96,7 +96,7 @@ export const getTopEmptyElement = (element: Element) => {
if (!topElement.parentElement.getAttribute("data-node-id")) { if (!topElement.parentElement.getAttribute("data-node-id")) {
topElement = topElement.parentElement; topElement = topElement.parentElement;
} else { } else {
let hasText = false let hasText = false;
Array.from(topElement.parentElement.querySelectorAll('[contenteditable="true"]')).find(item => { Array.from(topElement.parentElement.querySelectorAll('[contenteditable="true"]')).find(item => {
if (item.textContent.replace(Constants.ZWSP, "").replace("\n", "") !== "") { if (item.textContent.replace(Constants.ZWSP, "").replace("\n", "") !== "") {
hasText = true; hasText = true;

View file

@ -28,6 +28,7 @@ import {showMessage} from "../dialog/message";
import {replaceLocalPath} from "../editor/rename"; import {replaceLocalPath} from "../editor/rename";
import {editor} from "../config/editor"; import {editor} from "../config/editor";
import {goBack, goForward} from "./backForward"; 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") => { const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
if (key1 === "general") { if (key1 === "general") {
@ -381,7 +382,7 @@ const initWindow = () => {
winOnClose(currentWindow, close); winOnClose(currentWindow, close);
}); });
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => { ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
window.siyuan.printWin.destroy(); destroyPrintWindow();
}); });
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => { ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
dialog.showOpenDialog({ dialog.showOpenDialog({
@ -389,7 +390,7 @@ const initWindow = () => {
properties: ["createDirectory", "openDirectory"], properties: ["createDirectory", "openDirectory"],
}).then((result: OpenDialogReturnValue) => { }).then((result: OpenDialogReturnValue) => {
if (result.canceled) { if (result.canceled) {
window.siyuan.printWin.destroy(); destroyPrintWindow();
return; return;
} }
const msgId = showMessage(window.siyuan.languages.exporting, -1); const msgId = showMessage(window.siyuan.languages.exporting, -1);
@ -405,7 +406,7 @@ const initWindow = () => {
}, () => { }, () => {
const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf"); const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf");
fs.writeFileSync(pdfFilePath, pdfData); fs.writeFileSync(pdfFilePath, pdfData);
window.siyuan.printWin.destroy(); destroyPrintWindow();
fetchPost("/api/export/addPDFOutline", { fetchPost("/api/export/addPDFOutline", {
id: ipcData.rootId, id: ipcData.rootId,
path: pdfFilePath path: pdfFilePath
@ -437,11 +438,11 @@ const initWindow = () => {
}); });
}).catch((error: string) => { }).catch((error: string) => {
showMessage("Export PDF error:" + error, 0, "error", msgId); showMessage("Export PDF error:" + error, 0, "error", msgId);
window.siyuan.printWin.destroy(); destroyPrintWindow();
}); });
} catch (e) { } catch (e) {
showMessage("Export PDF failed: " + e, 0, "error", msgId); showMessage("Export PDF failed: " + e, 0, "error", msgId);
window.siyuan.printWin.destroy(); destroyPrintWindow();
} }
window.siyuan.printWin.hide(); window.siyuan.printWin.hide();
}); });