An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/9368 pdf
Vanessa7a70b532893a
diff --git a/app/electron/main.js b/app/electron/main.jsindex 5cbec9f24f..84e7fe17d1 100644--- a/app/electron/main.js+++ b/app/electron/main.js@@ -680,17 +680,26 @@ app.whenReady().then(() => {if (data.cmd === "askMicrophone") {return systemPreferences.askForMediaAccess("microphone");}+ if (data.cmd === "printToPDF") {+ return getWindowByContentId(data.webContentsId).webContents.printToPDF(data.pdfOptions);+ }});- ipcMain.on("siyuan-cmd", (event, cmd) => {+ ipcMain.on("siyuan-cmd", (event, data) => {+ let cmd = data;+ let webContentsId = event.sender.id+ if (typeof data !== "string") {+ cmd = data.cmd;+ webContentsId = data.webContentsId+ }switch (cmd) {case "openDevTools":event.sender.openDevTools({mode: "bottom"});break;case "show":- showWindow(getWindowByContentId(event.sender.id));+ showWindow(getWindowByContentId(webContentsId));break;case "hide":- getWindowByContentId(event.sender.id).hide();+ getWindowByContentId(webContentsId).hide();break;case "redo":event.sender.redo();@@ -698,6 +707,9 @@ app.whenReady().then(() => {case "undo":event.sender.undo();break;+ case "destroy":+ getWindowByContentId(webContentsId).destroy();+ break;}});ipcMain.on("siyuan-config-tray", (event, data) => {@@ -721,20 +733,37 @@ app.whenReady().then(() => {return;}data.filePaths = result.filePaths;+ data.webContentsId = event.sender.id;getWindowByContentId(event.sender.id).getParentWindow().send("siyuan-export-pdf", data);});});- ipcMain.on("siyuan-export-close", (event) => {- event.sender.destroy();- });- ipcMain.on("siyuan-export-prevent", (event, id) => {- BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {- const url = event.url;- event.preventDefault();- if (url.startsWith(localServer)) {+ ipcMain.on("siyuan-export-newwindow", (event, data) => {+ const printWin = new BrowserWindow({+ parent: getWindowByContentId(event.sender.id),+ modal: true,+ show: true,+ width: 1032,+ height: 650,+ resizable: false,+ frame: "darwin" === process.platform,+ icon: path.join(appDir, "stage", "icon-large.png"),+ titleBarStyle: "hidden",+ webPreferences: {+ contextIsolation: false,+ nodeIntegration: true,+ webviewTag: true,+ webSecurity: false,+ autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587+ },+ });+ printWin.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + printWin.webContents.userAgent;+ printWin.loadURL(data);+ printWin.webContents.on("will-navigate", (nEvent) => {+ nEvent.preventDefault();+ if (nEvent.url.startsWith(localServer)) {return;}- shell.openExternal(url);+ shell.openExternal(nEvent.url);});});ipcMain.on("siyuan-quit", (event, port) => {diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.tsindex 93baec7805..fdb31d56fd 100644--- a/app/src/boot/onGetConfig.ts+++ b/app/src/boot/onGetConfig.ts@@ -347,57 +347,57 @@ export const initWindow = (app: App) => {${response.data.replace("%pages", "<span class=totalPages></span>").replace("%page", "<span class=pageNumber></span>")}</div>`;}- window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {- fetchPost("/api/export/exportHTML", {+ const pdfData = await ipcRenderer.invoke(Constants.SIYUAN_GET, {+ cmd: "printToPDF",+ pdfOptions: ipcData.pdfOptions,+ webContentsId: ipcData.webContentsId+ });+ fetchPost("/api/export/exportHTML", {+ id: ipcData.rootId,+ pdf: true,+ removeAssets: ipcData.removeAssets,+ merge: ipcData.mergeSubdocs,+ savePath: ipcData.filePaths[0]+ }, () => {+ const pdfFilePath = path.join(ipcData.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");+ fs.writeFileSync(pdfFilePath, pdfData);+ ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "destroy", webContentsId: ipcData.webContentsId});+ fetchPost("/api/export/processPDF", {id: ipcData.rootId,- pdf: true,- removeAssets: ipcData.removeAssets,merge: ipcData.mergeSubdocs,- savePath: ipcData.filePaths[0]+ path: pdfFilePath,+ removeAssets: ipcData.removeAssets,}, () => {- const pdfFilePath = path.join(ipcData.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");- fs.writeFileSync(pdfFilePath, pdfData);- window.siyuan.printWin.destroy();- fetchPost("/api/export/processPDF", {- id: ipcData.rootId,- merge: ipcData.mergeSubdocs,- path: pdfFilePath,- removeAssets: ipcData.removeAssets,- }, () => {- afterExport(pdfFilePath, msgId);- if (ipcData.removeAssets) {- const removePromise = (dir: string) => {- return new Promise(function (resolve) {- //先读文件夹- fs.stat(dir, function (err, stat) {- if (stat) {- if (stat.isDirectory()) {- fs.readdir(dir, function (err, files) {- files = files.map(file => path.join(dir, file)); // a/b a/m- Promise.all(files.map(file => removePromise(file))).then(function () {- fs.rmdir(dir, resolve);- });+ afterExport(pdfFilePath, msgId);+ if (ipcData.removeAssets) {+ const removePromise = (dir: string) => {+ return new Promise(function (resolve) {+ //先读文件夹+ fs.stat(dir, function (err, stat) {+ if (stat) {+ if (stat.isDirectory()) {+ fs.readdir(dir, function (err, files) {+ files = files.map(file => path.join(dir, file)); // a/b a/m+ Promise.all(files.map(file => removePromise(file))).then(function () {+ fs.rmdir(dir, resolve);});- } else {- fs.unlink(dir, resolve);- }+ });+ } else {+ fs.unlink(dir, resolve);}- });+ }});- };- removePromise(path.join(ipcData.filePaths[0], "assets"));- }- });+ });+ };+ removePromise(path.join(ipcData.filePaths[0], "assets"));+ }});- }).catch((error: string) => {- showMessage("Export PDF error:" + error, 0, "error", msgId);- window.siyuan.printWin.destroy();});} catch (e) {showMessage("Export PDF failed: " + e, 0, "error", msgId);- window.siyuan.printWin.destroy();+ ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "destroy", webContentsId: ipcData.webContentsId});}- window.siyuan.printWin.hide();+ ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "hide", webContentsId: ipcData.webContentsId});});window.addEventListener("beforeunload", () => {diff --git a/app/src/constants.ts b/app/src/constants.tsindex b0aa2fb602..5d1d6c5f4c 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -41,8 +41,7 @@ export abstract class Constants {public static readonly SIYUAN_OPEN_FOLDER: string = "siyuan-open-folder";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";+ public static readonly SIYUAN_EXPORT_NEWWINDOW: string = "siyuan-export-newwindow";// custompublic static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.tsindex ee90e20000..d7e9ca2a4c 100644--- a/app/src/protyle/export/index.ts+++ b/app/src/protyle/export/index.ts@@ -2,7 +2,6 @@ import {hideMessage, showMessage} from "../../dialog/message";import {Constants} from "../../constants";/// #if !BROWSERimport {ipcRenderer} from "electron";-import {app, BrowserWindow, getCurrentWindow} from "@electron/remote";import * as fs from "fs";import * as path from "path";import {afterExport} from "./util";@@ -463,7 +462,7 @@ const renderPDF = (id: string) => {});actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {const {ipcRenderer} = require("electron");- ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")+ ipcRenderer.send("${Constants.SIYUAN_CMD}", "destroy")});actionElement.querySelector('.b3-button--text').addEventListener('click', () => {const {ipcRenderer} = require("electron");@@ -499,28 +498,8 @@ const renderPDF = (id: string) => {renderPreview(response.data.content);});</script></body></html>`;- window.siyuan.printWin = new BrowserWindow({- parent: getCurrentWindow(),- modal: true,- show: true,- width: 1032,- height: 650,- resizable: false,- frame: "darwin" === window.siyuan.config.system.os,- icon: path.join(window.siyuan.config.system.appDir, "stage", "icon-large.png"),- titleBarStyle: "hidden",- webPreferences: {- contextIsolation: false,- nodeIntegration: true,- webviewTag: true,- webSecurity: false,- autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587- },- });- 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);+ ipcRenderer.send(Constants.SIYUAN_EXPORT_NEWWINDOW, response.data.url);});};diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex d8d76c616a..d06185dfb0 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -327,7 +327,6 @@ interface ISiyuan {storage?: {[key: string]: any},- printWin?: import("electron").BrowserWindowtransactions?: {protyle: IProtyle,doOperations: IOperation[],