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: fix https://github.com/siyuan-note/siyuan/issues/5519
Vanessaf49dfa827363
diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.tsindex 059c0d341b..0208e38f86 100644--- a/app/src/menus/commonMenuItem.ts+++ b/app/src/menus/commonMenuItem.ts@@ -8,7 +8,7 @@ import {isLocalPath, movePathTo, pathPosix} from "../util/pathName";import {MenuItem} from "./Menu";import {hasClosestByClassName} from "../protyle/util/hasClosest";import {saveExport} from "../protyle/export";-import {writeText} from "../protyle/util/compatibility";+import {openByMobile, writeText} from "../protyle/util/compatibility";import {fetchPost} from "../util/fetch";import {hideMessage, showMessage} from "../dialog/message";import {Dialog} from "../dialog";@@ -652,13 +652,7 @@ export const exportMd = (id: string) => {id,}, response => {hideMessage(msgId);- if (window.siyuan.config.system.container === "ios") {- window.location.href = response.data.zip;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(response.data.zip);- } else {- window.open(response.data.zip);- }+ openByMobile(response.data.zip);});}}, {@@ -670,13 +664,7 @@ export const exportMd = (id: string) => {id,}, response => {hideMessage(msgId);- if (window.siyuan.config.system.container === "ios") {- window.location.href = response.data.zip;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(response.data.zip);- } else {- window.open(response.data.zip);- }+ openByMobile(response.data.zip);});}},@@ -774,13 +762,7 @@ export const openMenu = (src: string, onlyMenu = false) => {label: window.siyuan.languages.useBrowserView,accelerator: "Click",click: () => {- if (window.siyuan.config.system.container === "ios") {- window.location.href = src;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(src);- } else {- window.open(src);- }+ openByMobile(src);}});/// #endifdiff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex bd410dbe98..c5e7d7c60b 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -579,8 +579,11 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemegenImageWidthMenu(window.siyuan.languages.default, assetElement, imgElement, protyle, id, nodeElement, html),]}).element);- window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);- openMenu(imgElement.getAttribute("src"));+ const imgSrc = imgElement.getAttribute("src")+ if (imgSrc) {+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);+ openMenu(imgSrc);+ }window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});window.siyuan.menus.menu.element.querySelector("input").focus();};@@ -736,7 +739,9 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText}}).element);}- openMenu(linkAddress);+ if (linkAddress) {+ openMenu(linkAddress);+ }window.siyuan.menus.menu.element.classList.remove("fn__none");if (focusText || protyle.lute.IsValidLinkDest(linkAddress)) {window.siyuan.menus.menu.element.querySelectorAll("input")[1].select();@@ -812,10 +817,15 @@ export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {event.stopPropagation();});}- }, {- type: "separator"}];- return subMenus.concat(openMenu(iframeElement.getAttribute("src") || "", true) as IMenu[]);+ const iframeSrc = iframeElement.getAttribute("src");+ if (iframeSrc) {+ subMenus.push({+ type: "separator"+ })+ return subMenus.concat(openMenu(iframeSrc, true) as IMenu[]);+ }+ return subMenus;};export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string) => {@@ -833,11 +843,12 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)event.stopPropagation();});}- }, {- type: "separator"}];const src = videoElement.getAttribute("src");if (src.startsWith("assets/")) {+ subMenus.push({+ type: "separator"+ })subMenus.push({label: window.siyuan.languages.rename,click() {@@ -845,7 +856,11 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)}});}- return subMenus.concat(openMenu(videoElement.getAttribute("src"), true) as IMenu[]);+ const VideoSrc = videoElement.getAttribute("src");+ if (VideoSrc) {+ return subMenus.concat(openMenu(VideoSrc, true) as IMenu[]);+ }+ return subMenus;};export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: HTMLTableCellElement, range: Range) => {diff --git a/app/src/mobile/util/menu.ts b/app/src/mobile/util/menu.tsindex 1e8ddaaea6..3be8e1d9bc 100644--- a/app/src/mobile/util/menu.ts+++ b/app/src/mobile/util/menu.ts@@ -1,5 +1,5 @@import {fetchPost} from "../../util/fetch";-import {getEventName, writeText} from "../../protyle/util/compatibility";+import {getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";import {popSearch} from "./search";import {initAppearance} from "../settings/appearance";import {closePanel} from "./closePanel";@@ -382,11 +382,7 @@ ${accountHTML}});modelMainElement.querySelector("#exportData").addEventListener("click", () => {fetchPost("/api/export/exportData", {}, response => {- if (window.JSAndroid) {- window.JSAndroid.openExternal(response.data.zip);- return;- }- window.location.href = response.data.zip;+ openByMobile(response.data.zip);});});modelMainElement.querySelector("#importData").addEventListener("change", (event: InputEvent & { target: HTMLInputElement }) => {diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.tsindex 1f507cb88f..059dcad1d8 100644--- a/app/src/protyle/preview/index.ts+++ b/app/src/protyle/preview/index.ts@@ -1,4 +1,4 @@-import {getEventName, writeText} from "../util/compatibility";+import {getEventName, openByMobile, writeText} from "../util/compatibility";import {hasClosestByTag} from "../util/hasClosest";import {focusByRange} from "../util/selection";import {showMessage} from "../../dialog/message";@@ -38,11 +38,9 @@ export class Preview {if (event.target.tagName === "A") {const linkAddress = event.target.getAttribute("href");if (isMobile()) {- if (window.JSAndroid) {- window.JSAndroid.openExternal(linkAddress);- event.stopPropagation();- event.preventDefault();- }+ openByMobile(linkAddress);+ event.stopPropagation();+ event.preventDefault();return;}event.stopPropagation();diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.tsindex d6e3bbe07b..3cca3f8bfd 100644--- a/app/src/protyle/util/compatibility.ts+++ b/app/src/protyle/util/compatibility.ts@@ -1,3 +1,16 @@+export const openByMobile = (uri:string) => {+ if (!uri) {+ return;+ }+ if (window.siyuan.config.system.container === "ios") {+ window.location.href = uri;+ } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {+ window.JSAndroid.openExternal(uri);+ } else {+ window.open(uri);+ }+};+export const writeText = async (text: string) => {try {// navigator.clipboard.writeText 抛出异常不进入 catch,这里需要先处理移动端复制diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex e90dda63a7..bc602d3237 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -51,7 +51,7 @@ import {openAsset, openBy, openFileById} from "../../editor/util";import {openGlobalSearch} from "../../search/util";/// #endifimport {BlockPanel} from "../../block/Panel";-import {isCtrl} from "../util/compatibility";+import {isCtrl, openByMobile} from "../util/compatibility";import {MenuItem} from "../../menus/Menu";import {fetchPost} from "../../util/fetch";import {onGet} from "../util/onGet";@@ -1419,11 +1419,7 @@ export class WYSIWYG {const fileIds = fileElement.getAttribute("data-id").split("/");const linkAddress = `assets/${fileIds[1]}`;/// #if MOBILE- if (typeof window.JSAndroid === "undefined") {- window.open(linkAddress);- } else {- window.JSAndroid.openExternal(linkAddress);- }+ openByMobile(linkAddress)/// #elseif (window.siyuan.ctrlIsPressed) {openBy(linkAddress, "folder");@@ -1441,13 +1437,7 @@ export class WYSIWYG {event.preventDefault();const linkAddress = aElement.getAttribute("data-href");/// #if MOBILE- if (window.siyuan.config.system.container === "ios") {- window.location.href = linkAddress;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(linkAddress);- } else {- window.open(linkAddress);- }+ openByMobile(linkAddress);/// #elseif (isLocalPath(linkAddress)) {const linkPathname = linkAddress.split("?page")[0];@@ -1471,13 +1461,7 @@ export class WYSIWYG {openBy(linkAddress, "app");}/// #else- if (window.siyuan.config.system.container === "ios") {- window.location.href = linkAddress;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(linkAddress);- } else {- window.open(linkAddress);- }+ openByMobile(linkAddress)/// #endif}} else {@@ -1486,13 +1470,7 @@ export class WYSIWYG {showMessage(e);});/// #else- if (window.siyuan.config.system.container === "ios") {- window.location.href = linkAddress;- } else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {- window.JSAndroid.openExternal(linkAddress);- } else {- window.open(linkAddress);- }+ openByMobile(linkAddress)/// #endif}/// #endifdiff --git a/app/src/util/functions.ts b/app/src/util/functions.tsindex 81b874492e..4137178b16 100644--- a/app/src/util/functions.ts+++ b/app/src/util/functions.ts@@ -5,6 +5,7 @@ export const isMobile = () => {export const getRandom = (min: number, max: number) => {return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值};+export const getSearch = (key: string, link = window.location.search) => {if (link.indexOf("?") === -1) {return "";