diff --git a/app/electron/main.js b/app/electron/main.js index 63a2d2cff..9a0278fc5 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 f1db04b89..f3bdf0fe0 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 = ``; } + const currentWindowId = await ipcRenderer.invoke(Constants.SIYUAN_GET, { + cmd: "getCurrentWindowId", + }) // data-theme-mode="light" https://github.com/siyuan-note/siyuan/issues/7379 const html = ` @@ -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 = "";