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/16390
Vanessa22565b900607
diff --git a/app/electron/main.js b/app/electron/main.jsindex 5dc444b7b6..b8bb43c0db 100644--- a/app/electron/main.js+++ b/app/electron/main.js@@ -1051,25 +1051,6 @@ app.whenReady().then(() => {ipcMain.on("siyuan-quit", (event, port) => {exitApp(port);});- ipcMain.on("siyuan-reload-window", (event, port) => {- BrowserWindow.getAllWindows().forEach((item) => {- try {- const currentURL = new URL(item.getURL());- if (port.toString() === currentURL.port.toString()) {- const hasMain = workspaces.find((workspaceItem) => {- if (workspaceItem.browserWindow.id === item.id) {- return true;- }- });- if (!hasMain) {- item.reload();- }- }- } catch (e) {- // load file is not a url- }- });- });ipcMain.on("siyuan-show-window", (event) => {const mainWindow = getWindowByContentId(event.sender.id);if (!mainWindow) {diff --git a/app/src/config/appearance.ts b/app/src/config/appearance.tsindex 45666121b7..81f6a7de7f 100644--- a/app/src/config/appearance.ts+++ b/app/src/config/appearance.ts@@ -12,7 +12,6 @@ import {resetFloatDockSize} from "../layout/dock/util";import {confirmDialog} from "../dialog/confirmDialog";import {useShell} from "../util/pathName";import {Dialog} from "../dialog";-import {reloadOtherWindow} from "../dialog/processSystem";export const appearance = {element: undefined as Element,@@ -207,46 +206,7 @@ export const appearance = {msgTaskAssetDatabaseIndexCommitDisabled: statusBar ? statusBar.msgTaskAssetDatabaseIndexCommitDisabled : window.siyuan.config.appearance.statusBar.msgTaskAssetDatabaseIndexCommitDisabled,msgTaskHistoryGenerateFileDisabled: statusBar ? statusBar.msgTaskHistoryGenerateFileDisabled : window.siyuan.config.appearance.statusBar.msgTaskHistoryGenerateFileDisabled,}- }, async response => {- if (response.data.mode !== window.siyuan.config.appearance.mode ||- (response.data.mode === window.siyuan.config.appearance.mode && (- (response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||- (response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))- ) || response.data.lang !== window.siyuan.config.appearance.lang) {- reloadOtherWindow();- }- if (window.siyuan.config.appearance.themeJS) {- if (response.data.mode !== window.siyuan.config.appearance.mode ||- (response.data.mode === window.siyuan.config.appearance.mode && (- (response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||- (response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))- )- ) {- if (window.destroyTheme) {- try {- await window.destroyTheme();- window.destroyTheme = undefined;- document.getElementById("themeScript").remove();- } catch (e) {- console.error("destroyTheme error: " + e);- }- } else {- exportLayout({- errorExit: false,- cb() {- window.location.reload();- },- });- return;- }- }- }- appearance.onSetAppearance(response.data);- if (response.data.hideStatusBar) {- document.getElementById("status").classList.add("fn__none");- } else {- document.getElementById("status").classList.remove("fn__none");- }+ }, () => {resetFloatDockSize();});},diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex 21d0e10e3c..abcdf03a34 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -16,10 +16,7 @@ import {App} from "../index";import {escapeAttr} from "../util/escape";import {uninstall} from "../plugin/uninstall";import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader";-import {loadAssets} from "../util/assets";-import {addScript} from "../protyle/util/addScript";import {useShell} from "../util/pathName";-import {reloadOtherWindow} from "../dialog/processSystem";export const bazaar = {element: undefined as Element,@@ -674,28 +671,7 @@ export const bazaar = {mode: dataObj.themeMode === "dark" ? 1 : 0,frontend: getFrontend()}, async response => {- if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {- if (window.destroyTheme) {- try {- await window.destroyTheme();- window.destroyTheme = undefined;- document.getElementById("themeScript").remove();- } catch (e) {- console.error("destroyTheme error: " + e);- }- window.siyuan.config.appearance = response.data.appearance;- loadAssets(window.siyuan.config.appearance);- } else {- exportLayout({- cb() {- window.location.reload();- },- errorExit: false,- });- return;- }- }- bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));+ bazaar._onBazaar(response, bazaarType);bazaar._genMyHTML(bazaarType, app, false);if (bazaarType === "plugins") {if (window.siyuan.config.bazaar.petalDisabled) {@@ -757,45 +733,14 @@ export const bazaar = {frontend: getFrontend()}, async response => {this._genMyHTML(bazaarType, app);- bazaar._onBazaar(response, bazaarType, ["icons"].includes(bazaarType));+ bazaar._onBazaar(response, bazaarType);// https://github.com/siyuan-note/siyuan/issues/15177if (bazaarType === "themes" && response.data.appearance?.themeVer) {window.siyuan.config.appearance.themeVer = response.data.appearance.themeVer;}// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966// https://github.com/siyuan-note/siyuan/issues/5411- if (bazaarType === "themes" && (- (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === dataObj.name) ||- (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name)- )) {- const currentTheme = window.siyuan.config.appearance.mode === 1 ? window.siyuan.config.appearance.themeDark : window.siyuan.config.appearance.themeLight;- if (window.siyuan.config.appearance.themeJS) {- if (window.destroyTheme) {- try {- await window.destroyTheme();- window.destroyTheme = undefined;- document.getElementById("themeScript").remove();- addScript(`/appearance/themes/${currentTheme}/theme.js?v=${response.data.appearance.themeVer}`, "themeScript");- } catch (e) {- console.error("destroyTheme error: " + e);- }- } else {- exportLayout({- cb() {- window.location.reload();- },- errorExit: false,- });- return;- }- }- if ((window.siyuan.config.appearance.mode === 1 && currentTheme === "midnight") ||- (window.siyuan.config.appearance.mode !== 1 && currentTheme === "daylight")) {- (document.getElementById("themeDefaultStyle") as HTMLLinkElement).href = `/appearance/themes/${window.siyuan.config.appearance.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;- } else {- (document.getElementById("themeStyle") as HTMLLinkElement).href = `/appearance/themes/${currentTheme}/theme.css?v=${response.data.appearance.themeVer}`;- }- } else if (bazaarType === "plugins") {+ if (bazaarType === "plugins") {app.plugins.find((item: Plugin) => {if (item.name === dataObj.name) {reloadPlugin(app, {@@ -838,7 +783,7 @@ export const bazaar = {frontend: getFrontend()}, response => {this._genMyHTML(bazaarType, app);- bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));+ bazaar._onBazaar(response, bazaarType);});});}@@ -856,9 +801,8 @@ export const bazaar = {this._genMyHTML(bazaarType, app, false);fetchPost("/api/bazaar/getBazaarIcon", {}, response => {response.data.appearance = appearanceResponse.data;- bazaar._onBazaar(response, "icons", true);+ bazaar._onBazaar(response, "icons");bazaar._data.icons = response.data.packages;- reloadOtherWindow();});});} else if (bazaarType === "themes") {@@ -868,35 +812,10 @@ export const bazaar = {themeDark: mode === 1 ? packageName : window.siyuan.config.appearance.themeDark,themeLight: mode === 0 ? packageName : window.siyuan.config.appearance.themeLight,}), async (appearanceResponse) => {- reloadOtherWindow();- if ((mode !== window.siyuan.config.appearance.mode ||- (mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||- (mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&- window.siyuan.config.appearance.themeJS) {- if (window.destroyTheme) {- try {- await window.destroyTheme();- window.destroyTheme = undefined;- document.getElementById("themeScript").remove();- } catch (e) {- console.error("destroyTheme error: " + e);- }- window.siyuan.config.appearance = appearanceResponse.data;- loadAssets(window.siyuan.config.appearance);- } else {- exportLayout({- cb() {- window.location.reload();- },- errorExit: false,- });- return;- }- }this._genMyHTML("themes", app, false);fetchPost("/api/bazaar/getBazaarTheme", {}, response => {response.data.appearance = appearanceResponse.data;- bazaar._onBazaar(response, "themes", true);+ bazaar._onBazaar(response, "themes");bazaar._data.themes = response.data.packages;});});@@ -993,29 +912,29 @@ export const bazaar = {if (!item.getAttribute("data-init")) {if (type === "template") {fetchPost("/api/bazaar/getBazaarTemplate", {}, response => {- bazaar._onBazaar(response, "templates", false);+ bazaar._onBazaar(response, "templates");bazaar._data.templates = response.data.packages;});} else if (type === "icon") {fetchPost("/api/bazaar/getBazaarIcon", {}, response => {- bazaar._onBazaar(response, "icons", false);+ bazaar._onBazaar(response, "icons");bazaar._data.icons = response.data.packages;});} else if (type === "widget") {fetchPost("/api/bazaar/getBazaarWidget", {}, response => {- bazaar._onBazaar(response, "widgets", false);+ bazaar._onBazaar(response, "widgets");bazaar._data.widgets = response.data.packages;});} else if (type === "theme") {fetchPost("/api/bazaar/getBazaarTheme", {}, response => {- bazaar._onBazaar(response, "themes", false);+ bazaar._onBazaar(response, "themes");bazaar._data.themes = response.data.packages;});} else if (type === "plugin") {fetchPost("/api/bazaar/getBazaarPlugin", {frontend: getFrontend()}, response => {- bazaar._onBazaar(response, "plugins", false);+ bazaar._onBazaar(response, "plugins");bazaar._data.plugins = response.data.packages;});}@@ -1048,22 +967,22 @@ export const bazaar = {const type = (hasClosestByClassName(inputElement, "config-bazaar__panel") as HTMLElement).getAttribute("data-type");if (type === "template") {fetchPost("/api/bazaar/getBazaarTemplate", {keyword}, response => {- bazaar._onBazaar(response, "templates", false);+ bazaar._onBazaar(response, "templates");bazaar._data.templates = response.data.packages;});} else if (type === "icon") {fetchPost("/api/bazaar/getBazaarIcon", {keyword}, response => {- bazaar._onBazaar(response, "icons", false);+ bazaar._onBazaar(response, "icons");bazaar._data.icons = response.data.packages;});} else if (type === "widget") {fetchPost("/api/bazaar/getBazaarWidget", {keyword}, response => {- bazaar._onBazaar(response, "widgets", false);+ bazaar._onBazaar(response, "widgets");bazaar._data.widgets = response.data.packages;});} else if (type === "theme") {fetchPost("/api/bazaar/getBazaarTheme", {keyword}, response => {- bazaar._onBazaar(response, "themes", false);+ bazaar._onBazaar(response, "themes");bazaar._data.themes = response.data.packages;});} else if (type === "plugin") {@@ -1071,7 +990,7 @@ export const bazaar = {frontend: getFrontend(),keyword}, response => {- bazaar._onBazaar(response, "plugins", false);+ bazaar._onBazaar(response, "plugins");bazaar._data.plugins = response.data.packages;});} else if (type === "downloaded") {@@ -1148,7 +1067,7 @@ export const bazaar = {});});},- _onBazaar(response: IWebSocketData, bazaarType: TBazaarType, reload: boolean) {+ _onBazaar(response: IWebSocketData, bazaarType: TBazaarType) {if (bazaar.element.querySelector("#configBazaarReadme").classList.contains("config-bazaar__readme--show")) {const dataObj = JSON.parse(bazaar.element.querySelector("#configBazaarReadme > .item__side").getAttribute("data-obj"));bazaar._renderReadme((dataObj.bazaarType) as TBazaarType,@@ -1206,8 +1125,5 @@ export const bazaar = {html += '<div class="fn__flex-1" style="margin-left: 15px;min-width: 342px;"></div><div class="fn__flex-1" style="margin-left: 15px;min-width: 342px;"></div>';}element.innerHTML = `<div class="b3-cards">${html}</div>`;- if (reload) {- appearance.onSetAppearance(response.data.appearance);- }}};diff --git a/app/src/config/util/snippets.ts b/app/src/config/util/snippets.tsindex f7832561dd..9f9a120182 100644--- a/app/src/config/util/snippets.ts+++ b/app/src/config/util/snippets.ts@@ -3,7 +3,6 @@ import {Dialog} from "../../dialog";import {objEquals} from "../../util/functions";import {confirmDialog} from "../../dialog/confirmDialog";import {Constants} from "../../constants";-import {reloadOtherWindow} from "../../dialog/processSystem";export const renderSnippet = () => {fetchPost("/api/snippet/getSnippet", {type: "all", enabled: 2}, (response) => {@@ -225,10 +224,7 @@ const setSnippetPost = (dialog: Dialog, snippets: ISnippet[], removeIds: string[});window.siyuan.config.snippet.enabledCSS = (dialog.element.querySelector('.b3-switch[data-action="toggleCSS"]') as HTMLInputElement).checked;window.siyuan.config.snippet.enabledJS = (dialog.element.querySelector('.b3-switch[data-action="toggleJS"]') as HTMLInputElement).checked;- fetchPost("/api/setting/setSnippet", window.siyuan.config.snippet, () => {- reloadOtherWindow();- });- renderSnippet();+ fetchPost("/api/setting/setSnippet", window.siyuan.config.snippet);dialog.destroy({cancel: "true"});});};diff --git a/app/src/config/util/updateAppearance.ts b/app/src/config/util/updateAppearance.tsnew file mode 100644index 0000000000..48888071e0--- /dev/null+++ b/app/src/config/util/updateAppearance.ts@@ -0,0 +1,40 @@+import IAppearance = Config.IAppearance;+import {exportLayout} from "../../layout/util";+import {appearance} from "../appearance";++export const updateAppearance = async (data:IAppearance) => {+ if (window.siyuan.config.appearance.themeJS) {+ if (data.mode !== window.siyuan.config.appearance.mode ||+ (data.mode === window.siyuan.config.appearance.mode && (+ (data.mode === 0 && window.siyuan.config.appearance.themeLight !== data.themeLight) ||+ (data.mode === 1 && window.siyuan.config.appearance.themeDark !== data.themeDark))+ )+ ) {+ if (window.destroyTheme) {+ try {+ await window.destroyTheme();+ window.destroyTheme = undefined;+ document.getElementById("themeScript").remove();+ } catch (e) {+ console.error("destroyTheme error: " + e);+ }+ } else {+ exportLayout({+ errorExit: false,+ cb() {+ window.location.reload();+ },+ });+ return;+ }+ }+ }+ if (data.hideStatusBar !== window.siyuan.config.appearance.hideStatusBar) {+ if (data.hideStatusBar) {+ document.getElementById("status").classList.add("fn__none");+ } else {+ document.getElementById("status").classList.remove("fn__none");+ }+ }+ appearance.onSetAppearance(data);+}diff --git a/app/src/constants.ts b/app/src/constants.tsindex cfcc917001..3e4e13c008 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -57,7 +57,6 @@ export abstract class Constants {public static readonly SIYUAN_CONTEXT_MENU: string = "siyuan-context-menu";public static readonly SIYUAN_SHOW_WINDOW: string = "siyuan-show-window";- public static readonly SIYUAN_RELOAD_WINDOW: string = "siyuan-reload-window";// custompublic static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 5bdb5cc1ec..f18d50fc71 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -280,12 +280,6 @@ export const kernelError = () => {}};-export const reloadOtherWindow = () => {- /// #if !BROWSER- ipcRenderer.send(Constants.SIYUAN_RELOAD_WINDOW, location.port);- /// #endif-};-export const exitSiYuan = async () => {hideAllElements(["util"]);/// #if MOBILEdiff --git a/app/src/index.ts b/app/src/index.tsindex 847493c7c1..df7a5358bb 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -38,6 +38,8 @@ import {setLocalShorthandCount} from "./util/noRelyPCFunction";import {getDockByType} from "./layout/tabUtil";import {Tag} from "./layout/dock/Tag";import {updateControlAlt} from "./protyle/util/hotKey";+import {updateAppearance} from "./config/util/updateAppearance";+import {renderSnippet} from "./config/util/snippets";export class App {public plugins: import("./plugin").Plugin[] = [];@@ -69,6 +71,12 @@ export class App {});if (data) {switch (data.cmd) {+ case "setAppearance":+ updateAppearance(data.data);+ break;+ case "setSnippet":+ renderSnippet();+ break;case "setDefRefCount":setDefRefCount(data.data);break;diff --git a/app/src/mobile/settings/appearance.ts b/app/src/mobile/settings/appearance.tsindex f0f88f35ba..482eee9f49 100644--- a/app/src/mobile/settings/appearance.ts+++ b/app/src/mobile/settings/appearance.ts@@ -1,7 +1,6 @@import {fetchPost} from "../../util/fetch";import {genLangOptions, genOptions} from "../../util/genOptions";import {openModel} from "../menu/model";-import {reloadOtherWindow} from "../../dialog/processSystem";export const initAppearance = () => {openModel({@@ -55,10 +54,7 @@ export const initAppearance = () => {themeDark: (modelMainElement.querySelector("#themeDark") as HTMLSelectElement).value,themeLight: (modelMainElement.querySelector("#themeLight") as HTMLSelectElement).value,lang: (modelMainElement.querySelector("#lang") as HTMLSelectElement).value,- }), () => {- reloadOtherWindow();- window.location.reload();- });+ }));});});}diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.tsindex 035844c910..2ef0074024 100644--- a/app/src/mobile/util/onMessage.ts+++ b/app/src/mobile/util/onMessage.ts@@ -11,10 +11,17 @@ import {reloadPlugin} from "../../plugin/loader";import {reloadEmoji} from "../../emoji";import {setLocalShorthandCount} from "../../util/noRelyPCFunction";import {updateControlAlt} from "../../protyle/util/hotKey";+import {renderSnippet} from "../../config/util/snippets";export const onMessage = (app: App, data: IWebSocketData) => {if (data) {switch (data.cmd) {+ case "setAppearance":+ window.location.reload();+ break;+ case "setSnippet":+ renderSnippet();+ break;case "setDefRefCount":setDefRefCount(data.data);break;diff --git a/app/src/util/assets.ts b/app/src/util/assets.tsindex 55eb926b0d..6cf9df87f9 100644--- a/app/src/util/assets.ts+++ b/app/src/util/assets.ts@@ -6,9 +6,7 @@ import {getAllModels} from "../layout/getAll";import {exportLayout} from "../layout/util";/// #endifimport {fetchPost} from "./fetch";-import {appearance} from "../config/appearance";import {isInAndroid, isInHarmony, isInIOS, isIPad, isIPhone, isMac, isWin11} from "../protyle/util/compatibility";-import {reloadOtherWindow} from "../dialog/processSystem";export const loadAssets = (data: Config.IAppearance) => {const htmlElement = document.getElementsByTagName("html")[0];@@ -357,42 +355,7 @@ export const setMode = (modeElementValue: number) => {fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {mode,modeOS: modeElementValue === 2,- }), async response => {- if (response.data.mode !== window.siyuan.config.appearance.mode ||- (response.data.mode === window.siyuan.config.appearance.mode && (- (response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||- (response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))- )) {- reloadOtherWindow();- }- if (window.siyuan.config.appearance.themeJS) {- if (response.data.mode !== window.siyuan.config.appearance.mode ||- (response.data.mode === window.siyuan.config.appearance.mode && (- (response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||- (response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))- )- ) {- if (window.destroyTheme) {- try {- await window.destroyTheme();- window.destroyTheme = undefined;- document.getElementById("themeScript").remove();- } catch (e) {- console.error("destroyTheme error: " + e);- }- } else {- exportLayout({- errorExit: false,- cb() {- window.location.reload();- },- });- return;- }- }- }- appearance.onSetAppearance(response.data);- });+ }));/// #endif};diff --git a/app/src/window/index.ts b/app/src/window/index.tsindex eab152d41e..0da6a4b7da 100644--- a/app/src/window/index.ts+++ b/app/src/window/index.ts@@ -27,6 +27,8 @@ import {loadPlugins, reloadPlugin} from "../plugin/loader";import {hideAllElements} from "../protyle/ui/hideElements";import {reloadEmoji} from "../emoji";import {updateControlAlt} from "../protyle/util/hotKey";+import {updateAppearance} from "../config/util/updateAppearance";+import {renderSnippet} from "../config/util/snippets";class App {public plugins: import("../plugin").Plugin[] = [];@@ -56,6 +58,12 @@ class App {});if (data) {switch (data.cmd) {+ case "setAppearance":+ updateAppearance(data.data);+ break;+ case "setSnippet":+ renderSnippet();+ break;case "setDefRefCount":setDefRefCount(data.data);break;