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/8231
Vanessaf06a2e62a5ba
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.tsindex ea572c1540..14f492ff37 100644--- a/app/src/boot/onGetConfig.ts+++ b/app/src/boot/onGetConfig.ts@@ -172,7 +172,11 @@ export const initWindow = () => {focusByRange(getSelection().getRangeAt(0));}}- exportLayout(false);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: false+ });window.siyuan.altIsPressed = false;window.siyuan.ctrlIsPressed = false;window.siyuan.shiftIsPressed = false;@@ -184,26 +188,31 @@ export const initWindow = () => {};const winOnClose = (currentWindow: Electron.BrowserWindow, close = false) => {- exportLayout(false, () => {- if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {- // 最小化- if ("windows" === window.siyuan.config.system.os) {- ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, {- id: getCurrentWindow().id,- languages: window.siyuan.languages["_trayMenu"],- });- } else {- if (currentWindow.isFullScreen()) {- currentWindow.once("leave-full-screen", () => currentWindow.hide());- currentWindow.setFullScreen(false);+ exportLayout({+ reload: false,+ cb() {+ if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {+ // 最小化+ if ("windows" === window.siyuan.config.system.os) {+ ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, {+ id: getCurrentWindow().id,+ languages: window.siyuan.languages["_trayMenu"],+ });} else {- currentWindow.hide();+ if (currentWindow.isFullScreen()) {+ currentWindow.once("leave-full-screen", () => currentWindow.hide());+ currentWindow.setFullScreen(false);+ } else {+ currentWindow.hide();+ }}+ } else {+ exitSiYuan();}- } else {- exitSiYuan();- }- }, false, true);+ },+ onlyData: false,+ errorExit: true+ });};const winOnMaxRestore = () => {@@ -469,10 +478,18 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%padocument.querySelector(".toolbar").classList.add("toolbar--browser");}window.addEventListener("beforeunload", () => {- exportLayout(false);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: false+ });}, false);window.addEventListener("pagehide", () => {- exportLayout(false);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: false+ });}, false);/// #endif};diff --git a/app/src/config/about.ts b/app/src/config/about.tsindex 359e070147..a431439268 100644--- a/app/src/config/about.ts+++ b/app/src/config/about.ts@@ -323,23 +323,33 @@ export const about = {const networkServeElement = about.element.querySelector("#networkServe") as HTMLInputElement;networkServeElement.addEventListener("change", () => {fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {- exportLayout(false, () => {- exitSiYuan();- }, false, true);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: true,+ cb: exitSiYuan+ });});});const googleAnalyticsElement = about.element.querySelector("#googleAnalytics") as HTMLInputElement;googleAnalyticsElement.addEventListener("change", () => {fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });});});const uploadErrLogElement = about.element.querySelector("#uploadErrLog") as HTMLInputElement;uploadErrLogElement.addEventListener("change", () => {fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => {- exportLayout(false, () => {- exitSiYuan();- }, false, true);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: true,+ cb: exitSiYuan+ });});});const downloadInstallPkgElement = about.element.querySelector("#downloadInstallPkg") as HTMLInputElement;diff --git a/app/src/config/appearance.ts b/app/src/config/appearance.tsindex 463f094752..24fc38e418 100644--- a/app/src/config/appearance.ts+++ b/app/src/config/appearance.ts@@ -177,14 +177,22 @@ export const appearance = {window.siyuan.config.appearance.themeLight !== response.data.themeLight ||window.siyuan.config.appearance.themeDark !== response.data.themeDark)) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";if (response.data.modeOS && ((response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark"))) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}}@@ -215,7 +223,11 @@ export const appearance = {shell.openPath(path.join(window.siyuan.config.system.dataDir, "emojis"));});appearance.element.querySelector("#appearanceRefresh").addEventListener("click", () => {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });});/// #endifappearance.element.querySelectorAll("select").forEach(item => {@@ -231,7 +243,11 @@ export const appearance = {},onSetappearance(data: IAppearance) {if (data.lang !== window.siyuan.config.appearance.lang || data.nativeEmoji !== window.siyuan.config.appearance.nativeEmoji) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}window.siyuan.config.appearance = data;diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex 881631ef9e..0ed686c24a 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -482,7 +482,11 @@ export const bazaar = {mode: dataObj.themeMode === "dark" ? 1 : 0,}, response => {if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}bazaar._genMyHTML(bazaarType, app);@@ -525,7 +529,11 @@ export const bazaar = {(window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name))) {if (window.siyuan.config.appearance.themeJS) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });} else {const linkElement = (document.getElementById("themeDefaultStyle") as HTMLLinkElement);linkElement.href = linkElement.href + "1";@@ -563,7 +571,11 @@ export const bazaar = {bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));// TODO destroy pluginif (bazaarType === "plugins") {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });}});}@@ -596,7 +608,11 @@ export const bazaar = {(mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&window.siyuan.config.appearance.themeJS) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });} else {this._genMyHTML("themes", app);fetchPost("/api/bazaar/getBazaarTheme", {}, response => {@@ -628,7 +644,11 @@ export const bazaar = {enabled: (target as HTMLInputElement).checked}, () => {// TODO destroy plugin- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });});}event.stopPropagation();diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.tsindex 129d116c97..3437c1a419 100644--- a/app/src/config/keymap.ts+++ b/app/src/config/keymap.ts@@ -196,7 +196,11 @@ export const keymap = {},bindEvent() {keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });});const searchElement = keymap.element.querySelector("#keymapInput") as HTMLInputElement;const searchKeymapElement = keymap.element.querySelector("#searchByKey") as HTMLInputElement;diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 5219a899d6..c9a6940ff7 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -245,9 +245,12 @@ export const transactionError = () => {/// #if MOBILEexitSiYuan();/// #else- exportLayout(false, () => {- exitSiYuan();- }, false, true);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: true,+ cb: exitSiYuan+ });/// #endif});btnsElement[1].addEventListener("click", () => {diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex b4571227e5..97d466e41b 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -187,20 +187,26 @@ export const resetLayout = () => {});};-export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false, errorExit = false) => {+export const exportLayout = (options: {+ reload: boolean,+ cb?: () => void,+ onlyData: boolean,+ errorExit: boolean,+ dropEditScroll?: boolean+}) => {if (isWindow()) {const layoutJSON: any = {layout: {},};- layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);- if (onlyData) {+ layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);+ if (options.onlyData) {return layoutJSON;}sessionStorage.setItem("layout", JSON.stringify(layoutJSON));- if (reload) {+ if (options.reload) {window.location.reload();- } else if (cb) {- cb();+ } else if (options.cb) {+ options.cb();}return;}@@ -215,18 +221,18 @@ export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false,left: dockToJSON(window.siyuan.layout.leftDock),right: dockToJSON(window.siyuan.layout.rightDock),};- layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);- if (onlyData) {+ layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);+ if (options.onlyData) {return layoutJSON;}fetchPost("/api/system/setUILayout", {layout: layoutJSON,- errorExit // 后台不接受该参数,用于请求发生错误时退出程序+ errorExit: options.errorExit // 后台不接受该参数,用于请求发生错误时退出程序}, () => {- if (reload) {+ if (options.reload) {window.location.reload();- } else if (cb) {- cb();+ } else if (options.cb) {+ options.cb();}});};@@ -404,7 +410,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {}};-export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {+export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {if (layout instanceof Layout) {json.direction = layout.direction;if (layout.parent) {@@ -453,7 +459,9 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";json.instance = "Editor";- json.scrollAttr = saveScroll(layout.editor.protyle, true);+ if (!dropEditScroll) {+ json.scrollAttr = saveScroll(layout.editor.protyle, true);+ }} else if (layout instanceof Asset) {json.path = layout.path;if (layout.pdfObject) {@@ -517,13 +525,13 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {layout.children.forEach((item: Layout | Wnd | Tab) => {const itemJSON = {};json.children.push(itemJSON);- layoutToJSON(item, itemJSON);+ layoutToJSON(item, itemJSON, dropEditScroll);});}} else if (layout instanceof Tab) {if (layout.model) {json.children = {};- layoutToJSON(layout.model, json.children);+ layoutToJSON(layout.model, json.children, dropEditScroll);} else if (layout.headElement) {// 当前页签没有激活时编辑器没有初始化json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.tsindex 24f1f61b38..fcc03d3c3d 100644--- a/app/src/menus/workspace.ts+++ b/app/src/menus/workspace.ts@@ -137,7 +137,11 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {if (item.name === value) {saveDialog.destroy();confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => {- item.layout = exportLayout(false, undefined, true);+ item.layout = exportLayout({+ reload: false,+ onlyData: true,+ errorExit: false,+ });setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);});return true;@@ -148,7 +152,11 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {}window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({name: value,- layout: exportLayout(false, undefined, true)+ layout: exportLayout({+ reload: false,+ onlyData: true,+ errorExit: false,+ })});setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);saveDialog.destroy();diff --git a/app/src/util/assets.ts b/app/src/util/assets.tsindex f3508fbd2a..974199b0d6 100644--- a/app/src/util/assets.ts+++ b/app/src/util/assets.ts@@ -145,7 +145,11 @@ export const initAssets = () => {}, response => {if (window.siyuan.config.appearance.themeJS) {/// #if !MOBILE- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });/// #elsewindow.location.reload();/// #endif@@ -261,14 +265,22 @@ export const setMode = (modeElementValue: number) => {window.siyuan.config.appearance.themeLight !== response.data.themeLight ||window.siyuan.config.appearance.themeDark !== response.data.themeDark)) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";if (response.data.modeOS && ((response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark"))) {- exportLayout(true);+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ });return;}}diff --git a/app/src/util/processMessage.ts b/app/src/util/processMessage.tsindex 45f9549c02..c1674aa20f 100644--- a/app/src/util/processMessage.ts+++ b/app/src/util/processMessage.ts@@ -23,11 +23,12 @@ export const processMessage = (response: IWebSocketData) => {/// #if MOBILEwindow.location.reload();/// #else- if (response.data?.dropCurrentLayout) {- window.location.reload();- } else {- exportLayout(true);- }+ exportLayout({+ reload: true,+ onlyData: false,+ errorExit: false,+ dropEditScroll: response.data?.resetScroll,+ });/// #endifreturn false;}diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.tsindex 9bd8334d1b..d065482846 100644--- a/app/src/window/onWindowsMsg.ts+++ b/app/src/window/onWindowsMsg.ts@@ -15,11 +15,16 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {closeTab(ipcData);break;case "lockscreen":- exportLayout(false, () => {- fetchPost("/api/system/logoutAuth", {}, () => {- redirectToCheckAuth();- });- }, false, false);+ exportLayout({+ reload: false,+ onlyData: false,+ errorExit: false,+ cb() {+ fetchPost("/api/system/logoutAuth", {}, () => {+ redirectToCheckAuth();+ });+ }+ });break;}};