An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Improve encrypted notebook handling on mobile https://github.com/siyuan-note/siyuan/issues/18034
Daniela869fd0923f0
diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.tsindex 5503d6b70e..b4856bb63a 100644--- a/app/src/mobile/dock/MobileFiles.ts+++ b/app/src/mobile/dock/MobileFiles.ts@@ -208,15 +208,15 @@ export class MobileFiles extends Model {break;} else if (target.tagName === "LI") {this.setCurrent(target);+ const ulElement = hasTopClosestByTag(target, "UL");+ const notebookId = ulElement ? ulElement.getAttribute("data-url") : "";if (target.getAttribute("data-type") === "navigation-file") {- openMobileFileById(app, target.getAttribute("data-node-id"), [Constants.CB_GET_SCROLL]);+ openMobileFileById(app, target.getAttribute("data-node-id"), [Constants.CB_GET_SCROLL], undefined, notebookId);} else if (target.getAttribute("data-type") === "navigation-root") {const boxDocID = target.getAttribute("data-node-id");- const ulElement = hasTopClosestByTag(target, "UL");if (boxDocID) {- openMobileFileById(app, boxDocID, [Constants.CB_GET_SCROLL]);+ openMobileFileById(app, boxDocID, [Constants.CB_GET_SCROLL], undefined, notebookId);} else if (ulElement) {- const notebookId = ulElement.getAttribute("data-url");this.getLeaf(target, notebookId);}}diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.tsindex c9520661e2..c41898500e 100644--- a/app/src/mobile/editor.ts+++ b/app/src/mobile/editor.ts@@ -21,7 +21,7 @@ export const getCurrentEditor = () => {return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;};-export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL], scrollPosition?: ScrollLogicalPosition) => {+export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL], scrollPosition?: ScrollLogicalPosition, notebookId?: string) => {window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);const avPanelElement = document.querySelector(".av__panel");@@ -55,9 +55,10 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[}}+ const targetNotebookId = notebookId || window.siyuan.mobile.editor?.protyle?.notebookId;const blockInfoParam: IObject = {id};- if (isEncryptedBox(window.siyuan.mobile.editor?.protyle?.notebookId)) {- blockInfoParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;+ if (isEncryptedBox(targetNotebookId)) {+ blockInfoParam.notebook = targetNotebookId;}fetchPost("/api/block/getBlockInfo", blockInfoParam, (data) => {if (data.code === 3) {@@ -67,6 +68,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[const protyleOptions: IProtyleOptions = {blockId: id,rootId: data.data.rootID,+ notebookId: data.data.box,scrollPosition,action,render: {@@ -82,6 +84,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[}};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);@@ -108,7 +111,7 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,};- if (isEncryptedBox(window.siyuan.mobile.editor?.protyle?.notebookId)) {+ if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {getDocParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;}fetchPost("/api/filetree/getDoc", getDocParam, getResponse => {diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.tsindex 1a17b127b7..0c04314629 100644--- a/app/src/mobile/util/MobileBackFoward.ts+++ b/app/src/mobile/util/MobileBackFoward.ts@@ -17,6 +17,20 @@ import {isEncryptedBox} from "../../util/pathName";const forwardStack: IBackStack[] = [];+export const clearMobileBackForward = (notebookId?: string) => {+ if (!notebookId) {+ window.siyuan.backStack = [];+ forwardStack.length = 0;+ return;+ }+ window.siyuan.backStack = window.siyuan.backStack.filter(item => item.data?.notebookId !== notebookId);+ for (let i = forwardStack.length - 1; i >= 0; i--) {+ if (forwardStack[i].data?.notebookId === notebookId) {+ forwardStack.splice(i, 1);+ }+ }+};+const focusStack = (backStack: IBackStack) => {const protyle = getCurrentEditor().protyle;// 前进后快速后退会导致滚动错位 https://ld246.com/article/1734018624070diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.tsindex 12a122b10d..fc32e8f695 100644--- a/app/src/mobile/util/onMessage.ts+++ b/app/src/mobile/util/onMessage.ts@@ -12,6 +12,8 @@ import {reloadEmoji} from "../../emoji";import {renderSnippet} from "../../config/util/snippets";import {redirectToCheckAuth} from "../../util/pathName";import {reloadSync} from "../../util/reloadSync";+import {setEmpty} from "./setEmpty";+import {clearMobileBackForward} from "./MobileBackFoward";let statusTimeout: number;const statusElement = document.querySelector("#status") as HTMLElement;@@ -73,6 +75,18 @@ export const onMessage = (app: App, data: IWebSocketData) => {case "readonly":window.siyuan.config.editor.readOnly = data.data;break;+ case "closeBox":+ case "removeBox": {+ const closesCurrentEditor = window.siyuan.mobile.editor?.protyle.notebookId === data.data.box;+ clearMobileBackForward(closesCurrentEditor ? undefined : data.data.box);+ if (closesCurrentEditor) {+ window.siyuan.mobile.editor.destroy();+ window.siyuan.mobile.editor.protyle.element.innerHTML = "";+ window.siyuan.mobile.editor = undefined;+ setEmpty(app);+ }+ break;+ }case "setLocalStorageVal":window.siyuan.storage[data.data.key] = data.data.val;break;