Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle:

Vanessa0fc866b1a51a
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts
index bed8358d07..f94dd9de02 100644
--- a/app/src/dialog/processSystem.ts
+++ b/app/src/dialog/processSystem.ts
@@ -16,142 +16,12 @@ import {confirmDialog} from "./confirmDialog";
import {escapeHtml} from "../util/escape";
import {getWorkspaceName} from "../util/noRelyPCFunction";
import {needSubscribe} from "../util/needSubscribe";
-import {getDocDisplayName, setNoteBook} from "../util/pathName";
-import {reloadProtyle} from "../protyle/util/reload";
-import {Tab} from "../layout/Tab";
-import {setEmpty} from "../mobile/util/setEmpty";
-import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
+import {hideAllElements} from "../protyle/ui/hideElements";
import {App} from "../index";
import {saveScroll} from "../protyle/scroll/saveScroll";
import {isInAndroid, isInHarmony, isInIOS, setStorageVal} from "../protyle/util/compatibility";
import {Plugin} from "../plugin";
-const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
- fetchPost("/api/block/getDocInfo", {
- id: rootID
- }, (response) => {
- const titleEmpty = response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true";
- tab.updateTitle(getDocDisplayName(response.data.name, titleEmpty));
- if (protyle && protyle.title) {
- protyle.title.setTitle(response.data.name, titleEmpty);
- }
- });
-};
-
-export const reloadSync = (
- app: App,
- data: { upsertRootIDs: string[], removeRootIDs: string[] },
- hideMsg = true,
- // 同步的时候需要更新只读状态 https://github.com/siyuan-note/siyuan/issues/11517
- // 调整大纲的时候需要使用现有状态 https://github.com/siyuan-note/siyuan/issues/11808
- updateReadonly = true,
- onlyUpdateDoc = false
-) => {
- if (hideMsg) {
- hideMessage();
- }
- /// #if MOBILE
- if (window.siyuan.mobile.popEditor && window.siyuan.mobile.popEditor.protyle) {
- if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
- hideElements(["dialog"]);
- } else {
- reloadProtyle(window.siyuan.mobile.popEditor.protyle, false, updateReadonly);
- }
- }
- if (document.getElementById("empty").classList.contains("fn__none") &&
- window.siyuan.mobile.editor && window.siyuan.mobile.editor.protyle) {
- if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
- setEmpty(app);
- } else {
- reloadProtyle(window.siyuan.mobile.editor.protyle, false, updateReadonly);
- fetchPost("/api/block/getDocInfo", {
- id: window.siyuan.mobile.editor.protyle.block.rootID
- }, (response) => {
- setTitle(response.data.name);
- window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");
- });
- }
- }
- setNoteBook(() => {
- window.siyuan.mobile.docks.file.init(false);
- });
- /// #else
- const allModels = getAllModels();
- allModels.editor.forEach(item => {
- if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
- fetchPost("/api/block/getDocInfo", {
- id: item.editor.protyle.block.rootID,
- }, (response) => {
- item.editor.protyle.wysiwyg.renderCustom(response.data.ial);
- reloadProtyle(item.editor.protyle, false, updateReadonly);
- updateTitle(item.editor.protyle.block.rootID, item.parent, item.editor.protyle);
- });
- } else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
- item.parent.parent.removeTab(item.parent.id, false, false);
- delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID];
- setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
- }
- });
- allModels.graph.forEach(item => {
- if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
- item.parent.parent.removeTab(item.parent.id, false, false);
- } else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) {
- item.searchGraph(false);
- if (item.type === "local") {
- updateTitle(item.rootId, item.parent);
- }
- }
- });
- allModels.outline.forEach(item => {
- if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {
- item.parent.parent.removeTab(item.parent.id, false, false);
- } else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
- fetchPost("/api/outline/getDocOutline", {
- id: item.blockId,
- preview: item.isPreview
- }, response => {
- item.update(response);
- });
- if (item.type === "local") {
- updateTitle(item.blockId, item.parent);
- }
- }
- });
- allModels.backlink.forEach(item => {
- if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
- item.parent.parent.removeTab(item.parent.id, false, false);
- } else {
- item.refresh();
- if (item.type === "local") {
- updateTitle(item.rootId, item.parent);
- }
- }
- });
- if (!onlyUpdateDoc) {
- allModels.files.forEach(item => {
- setNoteBook(() => {
- item.init(false);
- });
- });
- }
- allModels.bookmark.forEach(item => {
- item.update();
- });
- allModels.tag.forEach(item => {
- item.update();
- });
- // NOTE asset 无法获取推送地址,先不处理
- allModels.search.forEach(item => {
- item.parent.panelElement.querySelector("#searchInput").dispatchEvent(new CustomEvent("input"));
- });
- allModels.custom.forEach(item => {
- if (item.update) {
- item.update();
- }
- });
- /// #endif
-};
-
export const setRefDynamicText = (data: {
"blockID": string,
"defBlockID": string,
diff --git a/app/src/index.ts b/app/src/index.ts
index 4e0b328d9f..5c6264f517 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -24,7 +24,6 @@ import {
progressBackgroundTask,
progressLoading,
progressStatus,
- reloadSync,
setDefRefCount,
setRefDynamicText,
setTitle,
@@ -48,6 +47,7 @@ import {Tag} from "./layout/dock/Tag";
import {updateAppearance} from "./config/util/updateAppearance";
import {renderSnippet} from "./config/util/snippets";
import {setBodyHighlight} from "./util/assets";
+import {reloadSync} from "./util/reloadSync";
export class App {
public plugins: import("./plugin").Plugin[] = [];
diff --git a/app/src/layout/Model.ts b/app/src/layout/Model.ts
index 8f0265fd72..01ea3be294 100644
--- a/app/src/layout/Model.ts
+++ b/app/src/layout/Model.ts
@@ -1,11 +1,11 @@
import {Constants} from "../constants";
/// #if !MOBILE
-import {Tab} from "./Tab";
+import type {Tab} from "./Tab";
/// #endif
-import {processMessage} from "../util/processMessage";
-import {reloadSync} from "../dialog/processSystem";
-import {App} from "../index";
+import type {App} from "../index";
import {kernelError} from "../util/kernelFault";
+import {processMessage} from "../util/processMessage";
+import {reloadSync} from "../util/reloadSync";
interface IConnectOptions {
id: string,
diff --git a/app/src/layout/Tab.ts b/app/src/layout/Tab.ts
index b3aae3d193..8db632be51 100644
--- a/app/src/layout/Tab.ts
+++ b/app/src/layout/Tab.ts
@@ -1,6 +1,6 @@
import {Wnd} from "./Wnd";
import {genUUID} from "../util/genID";
-import {Model} from "./Model";
+import type {Model} from "./Model";
import {Editor} from "../editor";
import {hasClosestByTag} from "../protyle/util/hasClosest";
import {Constants} from "../constants";
diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts
index 91ef95b701..12a122b10d 100644
--- a/app/src/mobile/util/onMessage.ts
+++ b/app/src/mobile/util/onMessage.ts
@@ -2,7 +2,6 @@ import {openMobileFileById} from "../editor";
import {
processSync,
progressLoading,
- reloadSync,
setDefRefCount,
setRefDynamicText,
transactionError
@@ -12,6 +11,7 @@ import {reloadPlugin} from "../../plugin/loader";
import {reloadEmoji} from "../../emoji";
import {renderSnippet} from "../../config/util/snippets";
import {redirectToCheckAuth} from "../../util/pathName";
+import {reloadSync} from "../../util/reloadSync";
let statusTimeout: number;
const statusElement = document.querySelector("#status") as HTMLElement;
diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts
index d7686e93d5..34297be943 100644
--- a/app/src/util/fetch.ts
+++ b/app/src/util/fetch.ts
@@ -5,13 +5,13 @@ import {ipcRenderer} from "electron";
import {processMessage} from "./processMessage";
import {kernelError} from "./kernelFault";
-export function fetchPost(
+export const fetchPost = (
url: string,
data?: any,
cb?: (response: IWebSocketData) => void,
headers?: IObject,
failCallback?: (response: IWebSocketData) => void,
- signal?: AbortSignal) {
+ signal?: AbortSignal) => {
const init: RequestInit = {
method: "POST",
};
@@ -123,7 +123,7 @@ export function fetchPost(
});
};
-export async function fetchSyncPost(url: string, data?: any) {
+export const fetchSyncPost = async (url: string, data?: any) => {
const init: RequestInit = {
method: "POST",
};
@@ -140,7 +140,7 @@ export async function fetchSyncPost(url: string, data?: any) {
return res2;
};
-export function fetchGet(url: string, cb: (response: IWebSocketData | IObject | string) => void) {
+export const fetchGet = (url: string, cb: (response: IWebSocketData | IObject | string) => void) => {
fetch(url).then((response) => {
if (response.headers.get("content-type")?.indexOf("application/json") > -1) {
return response.json();
diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.ts
new file mode 100644
index 0000000000..5449b840ff
--- /dev/null
+++ b/app/src/util/reloadSync.ts
@@ -0,0 +1,138 @@
+import type {App} from "../index";
+import {hideMessage} from "../dialog/message";
+import {hideElements} from "../protyle/ui/hideElements";
+import {reloadProtyle} from "../protyle/util/reload";
+import {setEmpty} from "../mobile/util/setEmpty";
+import {fetchPost} from "./fetch";
+import {Constants} from "../constants";
+import {getDocDisplayName, setNoteBook} from "./pathName";
+import {getAllModels} from "../layout/getAll";
+import {setStorageVal} from "../protyle/util/compatibility";
+import {setTitle} from "../dialog/processSystem";
+import type {Tab} from "../layout/Tab";
+
+const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
+ fetchPost("/api/block/getDocInfo", {
+ id: rootID
+ }, (response) => {
+ const titleEmpty = response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true";
+ tab.updateTitle(getDocDisplayName(response.data.name, titleEmpty));
+ if (protyle && protyle.title) {
+ protyle.title.setTitle(response.data.name, titleEmpty);
+ }
+ });
+};
+
+export const reloadSync = (
+ app: App,
+ data: { upsertRootIDs: string[], removeRootIDs: string[] },
+ hideMsg = true,
+ // 同步的时候需要更新只读状态 https://github.com/siyuan-note/siyuan/issues/11517
+ // 调整大纲的时候需要使用现有状态 https://github.com/siyuan-note/siyuan/issues/11808
+ updateReadonly = true,
+ onlyUpdateDoc = false
+) => {
+ if (hideMsg) {
+ hideMessage();
+ }
+ /// #if MOBILE
+ if (window.siyuan.mobile.popEditor && window.siyuan.mobile.popEditor.protyle) {
+ if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
+ hideElements(["dialog"]);
+ } else {
+ reloadProtyle(window.siyuan.mobile.popEditor.protyle, false, updateReadonly);
+ }
+ }
+ if (document.getElementById("empty").classList.contains("fn__none") &&
+ window.siyuan.mobile.editor && window.siyuan.mobile.editor.protyle) {
+ if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
+ setEmpty(app);
+ } else {
+ reloadProtyle(window.siyuan.mobile.editor.protyle, false, updateReadonly);
+ fetchPost("/api/block/getDocInfo", {
+ id: window.siyuan.mobile.editor.protyle.block.rootID
+ }, (response) => {
+ setTitle(response.data.name);
+ window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");
+ });
+ }
+ }
+ setNoteBook(() => {
+ window.siyuan.mobile.docks.file.init(false);
+ });
+ /// #else
+ const allModels = getAllModels();
+ allModels.editor.forEach(item => {
+ if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
+ fetchPost("/api/block/getDocInfo", {
+ id: item.editor.protyle.block.rootID,
+ }, (response) => {
+ item.editor.protyle.wysiwyg.renderCustom(response.data.ial);
+ reloadProtyle(item.editor.protyle, false, updateReadonly);
+ updateTitle(item.editor.protyle.block.rootID, item.parent, item.editor.protyle);
+ });
+ } else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
+ item.parent.parent.removeTab(item.parent.id, false, false);
+ delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID];
+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
+ }
+ });
+ allModels.graph.forEach(item => {
+ if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
+ item.parent.parent.removeTab(item.parent.id, false, false);
+ } else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) {
+ item.searchGraph(false);
+ if (item.type === "local") {
+ updateTitle(item.rootId, item.parent);
+ }
+ }
+ });
+ allModels.outline.forEach(item => {
+ if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {
+ item.parent.parent.removeTab(item.parent.id, false, false);
+ } else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
+ fetchPost("/api/outline/getDocOutline", {
+ id: item.blockId,
+ preview: item.isPreview
+ }, response => {
+ item.update(response);
+ });
+ if (item.type === "local") {
+ updateTitle(item.blockId, item.parent);
+ }
+ }
+ });
+ allModels.backlink.forEach(item => {
+ if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
+ item.parent.parent.removeTab(item.parent.id, false, false);
+ } else {
+ item.refresh();
+ if (item.type === "local") {
+ updateTitle(item.rootId, item.parent);
+ }
+ }
+ });
+ if (!onlyUpdateDoc) {
+ allModels.files.forEach(item => {
+ setNoteBook(() => {
+ item.init(false);
+ });
+ });
+ }
+ allModels.bookmark.forEach(item => {
+ item.update();
+ });
+ allModels.tag.forEach(item => {
+ item.update();
+ });
+ // NOTE asset 无法获取推送地址,先不处理
+ allModels.search.forEach(item => {
+ item.parent.panelElement.querySelector("#searchInput").dispatchEvent(new CustomEvent("input"));
+ });
+ allModels.custom.forEach(item => {
+ if (item.update) {
+ item.update();
+ }
+ });
+ /// #endif
+};
diff --git a/app/src/window/index.ts b/app/src/window/index.ts
index 22b819d061..9826e7a6a3 100644
--- a/app/src/window/index.ts
+++ b/app/src/window/index.ts
@@ -13,7 +13,6 @@ import {
progressBackgroundTask,
progressLoading,
progressStatus,
- reloadSync,
setDefRefCount,
setRefDynamicText,
setTitle,
@@ -29,6 +28,7 @@ import {reloadEmoji} from "../emoji";
import {updateAppearance} from "../config/util/updateAppearance";
import {renderSnippet} from "../config/util/snippets";
import {setBodyHighlight} from "../util/assets";
+import {reloadSync} from "../util/reloadSync";
class App {
public plugins: import("../plugin").Plugin[] = [];