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/16198
Vanessacd3629901bc7
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.tsindex 30b8ace052..b5b2766341 100644--- a/app/src/mobile/editor.ts+++ b/app/src/mobile/editor.ts@@ -21,6 +21,21 @@ export const getCurrentEditor = () => {return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;};+// 串行更新时间,避免快速切换文档时较早的关闭请求覆盖较新的打开状态。+let recentDocSwitchPromise = Promise.resolve();+type TRecentDocUpdateType = "open" | "view" | "switch";+export const updateRecentDocSwitchTime = (type: TRecentDocUpdateType, rootID: string, previousRootID?: string) => {+ recentDocSwitchPromise = recentDocSwitchPromise.then(async () => {+ if (type === "view") {+ return fetchPost("/api/storage/updateRecentDocViewTime", {rootID});+ }+ if (type === "switch" && previousRootID) {+ await fetchPost("/api/storage/updateRecentDocCloseTime", {rootID: previousRootID});+ }+ return fetchPost("/api/storage/updateRecentDocOpenTime", {rootID});+ });+};+export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL],scrollPosition?: ScrollLogicalPosition, notebookId?: string,afterOpen?: (protyle: IProtyle) => void, forceReload = false) => {@@ -52,7 +67,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[}closePanel();// 更新文档浏览时间- fetchPost("/api/storage/updateRecentDocViewTime", {rootID: window.siyuan.mobile.editor.protyle.block.rootID});+ updateRecentDocSwitchTime("view", window.siyuan.mobile.editor.protyle.block.rootID);afterOpen?.(window.siyuan.mobile.editor.protyle);return;}@@ -72,6 +87,9 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[action.includes(Constants.CB_GET_ALL) &&action.includes(Constants.CB_GET_FOCUS);const actionList = isRootFocus ? action.filter((item) => item !== Constants.CB_GET_ALL) : action;+ const previousRootID = window.siyuan.mobile.editor?.protyle.block.rootID;+ const recentDocUpdateType: TRecentDocUpdateType = !previousRootID ? "open" :+ previousRootID === data.data.rootID ? "view" : "switch";const protyleOptions: IProtyleOptions = {databaseAttr: true,blockId: id,@@ -90,18 +108,18 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[preview: {actions: ["mp-wechat", "zhihu", "yuque"]},- after: (editor) => afterOpen?.(editor.protyle),+ after: (editor) => {+ updateRecentDocSwitchTime(recentDocUpdateType, data.data.rootID, previousRootID);+ afterOpen?.(editor.protyle);+ },};if (window.siyuan.mobile.editor) {window.siyuan.mobile.editor.protyle.notebookId = data.data.box;window.siyuan.mobile.editor.protyle.title.element.removeAttribute("data-render");pushBack();addLoading(window.siyuan.mobile.editor.protyle);- if (window.siyuan.mobile.editor.protyle.block.rootID !== data.data.rootID) {+ if (previousRootID !== data.data.rootID) {window.siyuan.mobile.editor.protyle.wysiwyg.element.innerHTML = "";- fetchPost("/api/storage/updateRecentDocOpenTime", {rootID: data.data.rootID});- } else {- fetchPost("/api/storage/updateRecentDocViewTime", {rootID: data.data.rootID});}if (actionList.includes(Constants.CB_GET_SCROLL) && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID]) {getDocByScroll({@@ -109,6 +127,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID],mergedOptions: protyleOptions,cb() {+ updateRecentDocSwitchTime(recentDocUpdateType, data.data.rootID, previousRootID);app.plugins.forEach(item => {item.eventBus.emit("switch-protyle", {protyle: window.siyuan.mobile.editor.protyle});});@@ -131,6 +150,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[action: actionList,scrollPosition,afterCB() {+ updateRecentDocSwitchTime(recentDocUpdateType, data.data.rootID, previousRootID);app.plugins.forEach(item => {item.eventBus.emit("switch-protyle", {protyle: window.siyuan.mobile.editor.protyle});});@@ -145,7 +165,6 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[initMirror(window.siyuan.mobile.editor.protyle.block.rootID);}} else {- fetchPost("/api/storage/updateRecentDocOpenTime", {rootID: data.data.rootID});window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), protyleOptions);}setEditor();diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.tsindex 8d36f181db..1e1c89f803 100644--- a/app/src/mobile/util/MobileBackFoward.ts+++ b/app/src/mobile/util/MobileBackFoward.ts@@ -10,7 +10,7 @@ import {disabledForeverProtyle, setReadonlyByConfig} from "../../protyle/util/onimport {setStorageVal} from "../../protyle/util/compatibility";import {closePanel} from "./closePanel";import {showMessage} from "../../dialog/message";-import {getCurrentEditor} from "../editor";+import {getCurrentEditor, updateRecentDocSwitchTime} from "../editor";import {avRender} from "../../protyle/render/av/render";import {setTitle} from "../../util/processTitle";import {isEncryptedBox} from "../../util/pathName";@@ -33,6 +33,10 @@ export const clearMobileBackForward = (notebookId?: string) => {const focusStack = (backStack: IBackStack) => {const protyle = getCurrentEditor().protyle;+ const updateRecentDocTime = (previousRootID: string) => {+ updateRecentDocSwitchTime(previousRootID === backStack.data.rootID ? "view" : "switch",+ backStack.data.rootID, previousRootID);+ };// 前进后快速后退会导致滚动错位 https://ld246.com/article/1734018624070protyle.observerLoad?.disconnect();@@ -76,17 +80,20 @@ const focusStack = (backStack: IBackStack) => {if (backStack.zoomId !== protyle.block.id) {fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {if (existResponse.data) {+ const previousRootID = protyle.block.rootID;zoomOut({protyle,id: backStack.id,isPushBack: false,callback: () => {+ updateRecentDocTime(previousRootID);protyle.contentElement.scrollTop = backStack.scrollTop;}});}});} else {+ updateRecentDocTime(protyle.block.rootID);protyle.contentElement.scrollTop = backStack.scrollTop;}exitFocusElement.classList.remove("fn__none");@@ -102,6 +109,10 @@ const focusStack = (backStack: IBackStack) => {getDocParam.notebook = protyle.notebookId;}fetchPost("/api/filetree/getDoc", getDocParam, getResponse => {+ if (getResponse.code !== 0) {+ return;+ }+ const previousRootID = protyle.block.rootID;protyle.block.parentID = getResponse.data.parentID;protyle.block.parent2ID = getResponse.data.parent2ID;protyle.block.rootID = getResponse.data.rootID;@@ -132,6 +143,7 @@ const focusStack = (backStack: IBackStack) => {item.eventBus.emit("switch-protyle", {protyle});item.eventBus.emit("loaded-protyle-static", {protyle});});+ updateRecentDocTime(previousRootID);exitFocusElement.classList.add("fn__none");});};@@ -146,6 +158,7 @@ export const pushBack = () => {endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),notebookId: protyle.notebookId,path: protyle.path,+ rootID: protyle.block.rootID,},scrollTop: protyle.contentElement.scrollTop,callback: protyle.block.action,@@ -208,6 +221,7 @@ export const goBack = () => {endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),notebookId: protyle.notebookId,path: protyle.path,+ rootID: protyle.block.rootID,},scrollTop: protyle.contentElement.scrollTop,callback: protyle.block.action,