From e14e8749c9169f75875536f45a77a7723331938c Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 12 Jan 2023 16:11:51 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/7054 --- app/electron/main.js | 11 +++++++++++ app/src/constants.ts | 1 + app/src/protyle/export/index.ts | 13 +++---------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index c3f277e6f..1822fc773 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -660,6 +660,17 @@ app.whenReady().then(() => { ipcMain.on('siyuan-export-close', (event, id) => { BrowserWindow.fromId(id).webContents.send('siyuan-export-close', id) }) + ipcMain.on('siyuan-export-prevent', (event, id) => { + BrowserWindow.fromId(id).webContents.on('will-navigate', (event, url) => { + const currentURL = new URL(event.sender.getURL()) + if (url.startsWith(getServer(currentURL.port))) { + return + } + + event.preventDefault() + shell.openExternal(url) + }) + }) ipcMain.on('siyuan-quit', (event, id) => { const mainWindow = BrowserWindow.fromId(id) let tray diff --git a/app/src/constants.ts b/app/src/constants.ts index 61cf0b31b..dec64ac2b 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -31,6 +31,7 @@ export abstract class Constants { public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close"; public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf"; public static readonly SIYUAN_EXPORT_CLOSE: string = "siyuan-export-close"; + public static readonly SIYUAN_EXPORT_PREVENT: string = "siyuan-export-prevent"; // size public static readonly SIZE_TOOLBAR_HEIGHT: number = 42; diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 4fe61b440..745c0d5b4 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -1,7 +1,7 @@ import {hideMessage, showMessage} from "../../dialog/message"; import {Constants} from "../../constants"; /// #if !BROWSER -import {OpenDialogReturnValue, shell} from "electron"; +import {OpenDialogReturnValue, ipcRenderer} from "electron"; import {app, BrowserWindow, dialog, getCurrentWindow} from "@electron/remote"; import * as fs from "fs"; import * as path from "path"; @@ -451,9 +451,8 @@ const renderPDF = (id: string) => { renderPreview(response.data.content); }); `; - const mainWindow = getCurrentWindow(); window.siyuan.printWin = new BrowserWindow({ - parent: mainWindow, + parent: getCurrentWindow(), modal: true, show: true, width: 1032, @@ -469,13 +468,7 @@ const renderPDF = (id: string) => { webSecurity: false, }, }); - window.siyuan.printWin.webContents.on('will-navigate', (event, url) => { - if (url.indexOf(location.host) > -1) { - return - } - event.preventDefault() - shell.openExternal(url) - }) + ipcRenderer.send(Constants.SIYUAN_EXPORT_PREVENT, window.siyuan.printWin.id); window.siyuan.printWin.webContents.userAgent = `SiYuan/${app.getVersion()} https://b3log.org/siyuan Electron`; fetchPost("/api/export/exportTempContent", {content: html}, (response) => { window.siyuan.printWin.loadURL(response.data.url);