Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve PDF export preview behavior when canceling destination selection https://github.com/siyuan-note/siyuan/issues/17728

Daniel327237018dd3
diff --git a/app/electron/main.js b/app/electron/main.js
index 5475d71c01..f2817d1cb0 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -1773,17 +1773,8 @@ app.whenReady().then(() => {
});
});
ipcMain.on("siyuan-export-pdf", (event, data) => {
- dialog.showOpenDialog({
- title: data.title, properties: ["createDirectory", "openDirectory"],
- }).then((result) => {
- if (result.canceled) {
- event.sender.destroy();
- return;
- }
- data.filePaths = result.filePaths;
- data.webContentsId = event.sender.id;
- getWindowByContentId(data.parentWindowId).send("siyuan-export-pdf", data);
- });
+ data.webContentsId = event.sender.id;
+ getWindowByContentId(data.parentWindowId).send("siyuan-export-pdf", data);
});
ipcMain.on("siyuan-export-newwindow", (event, data) => {
// The PDF/Word export preview window automatically adjusts according to the size of the main window https://github.com/siyuan-note/siyuan/issues/10554
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 85d9625554..4694eed793 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -672,9 +672,18 @@ ${getIconScript(servePath)}
parentWindowId: ${currentWindowId},
};
};
- actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
+ actionElement.querySelector('.b3-button--text').addEventListener('click', async () => {
const {ipcRenderer} = require("electron");
+ const result = await ipcRenderer.invoke("${Constants.SIYUAN_GET}", {
+ cmd: "showOpenDialog",
+ title: "${window.siyuan.languages.export} PDF",
+ properties: ["createDirectory", "openDirectory"],
+ });
+ if (result.canceled || result.filePaths.length === 0) {
+ return;
+ }
const isPaged = actionElement.querySelector("#paged").checked;
+ let exportConfig;
if (!isPaged) {
const getPageSizeDimensions = () => {
// https://github.com/electron/electron/blob/3df3a6a736b93e0d69fa3b0c403b33f201287780/lib/browser/api/web-contents.ts#L89-L101
@@ -689,21 +698,23 @@ ${getIconScript(servePath)}
return pageSizes[actionElement.querySelector("#pageSize").value];
};
const previewHeight = Math.max(previewElement.scrollHeight / 96 - (parseFloat(document.querySelector("#marginsTop").value) || 0) - (parseFloat(document.querySelector("#marginsBottom").value) || 0), getPageSizeDimensions().height);
- ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", buildExportConfig(actionElement.querySelector("#landscape").checked ? {
+ exportConfig = buildExportConfig(actionElement.querySelector("#landscape").checked ? {
height: getPageSizeDimensions().height,
width: previewHeight,
} : {
width: getPageSizeDimensions().width,
height: previewHeight,
- }));
+ });
} else {
- ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", buildExportConfig());
+ exportConfig = buildExportConfig();
}
+ exportConfig.filePaths = result.filePaths;
document.body.classList.add("exporting");
previewElement.style.zoom = "";
previewElement.style.padding = "6px 0 0 0";
fixBlockWidth();
actionElement.remove();
+ ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", exportConfig);
});
setPadding();
renderPreview(response.data);