Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/10711

Vanessaf72320642320
diff --git a/app/electron/main.js b/app/electron/main.js
index 63a2d2cffd..9a0278fc57 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -700,6 +700,9 @@ app.whenReady().then(() => {
if (data.cmd === "showOpenDialog") {
return dialog.showOpenDialog(data);
}
+ if (data.cmd === "getCurrentWindowId") {
+ return event.sender.id;
+ }
if (data.cmd === "setProxy") {
return setProxy(data.proxyURL, event.sender);
}
@@ -904,26 +907,12 @@ app.whenReady().then(() => {
}
data.filePaths = result.filePaths;
data.webContentsId = event.sender.id;
- const wnd = getWindowByContentId(event.sender.id);
- if (!wnd) {
- // 文档已经被删除的情况下关闭窗口,下同
- event.sender.destroy();
- return;
- }
- const parentWnd = wnd.getParentWindow();
- if (!parentWnd) {
- event.sender.destroy();
- return;
- }
- parentWnd.send("siyuan-export-pdf", data);
+ getWindowByContentId(data.parentWindowId).send("siyuan-export-pdf", data);
});
});
ipcMain.on("siyuan-export-newwindow", (event, data) => {
- const parentWnd = getWindowByContentId(event.sender.id);
- const parentWndBounds = parentWnd.getBounds();
+ const parentWndBounds = getWindowByContentId(event.sender.id).getBounds();
const parentWndScreen = screen.getDisplayNearestPoint({x: parentWndBounds.x, y: parentWndBounds.y});
- parentWndScreen.size.width;
-
// The PDF/Word export preview window automatically adjusts according to the size of the main window https://github.com/siyuan-note/siyuan/issues/10554
const printWin = new BrowserWindow({
show: true,
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index f1db04b893..f3bdf0fe02 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -81,7 +81,7 @@ const getSnippetCSS = () => {
};
/// #if !BROWSER
-const renderPDF = (id: string) => {
+const renderPDF = async (id: string) => {
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
const servePath = window.location.protocol + "//" + window.location.host;
const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight");
@@ -89,6 +89,9 @@ const renderPDF = (id: string) => {
if (!isDefault) {
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}/appearance/themes/${window.siyuan.config.appearance.themeLight}/theme.css?${Constants.SIYUAN_VERSION}"/>`;
}
+ const currentWindowId = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
+ cmd: "getCurrentWindowId",
+ })
// data-theme-mode="light" https://github.com/siyuan-note/siyuan/issues/7379
const html = `<!DOCTYPE html>
<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="light" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
@@ -542,6 +545,7 @@ const renderPDF = (id: string) => {
removeAssets: actionElement.querySelector("#removeAssets").checked,
rootId: "${id}",
rootTitle: response.data.name,
+ parentWindowId: ${currentWindowId},
})
previewElement.classList.add("exporting");
previewElement.style.zoom = "";