Skip to content

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

:art: https://github.com/siyuan-note/siyuan/pull/16465

Vanessa341ef4ed4c38
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index ec4d031e70..da840f1942 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -14,7 +14,7 @@ import {appearance} from "../config/appearance";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {initAssets, setInlineStyle} from "../util/assets";
import {renderSnippet} from "../config/util/snippets";
-import {openFile, openFileById} from "../editor/util";
+import {openFile} from "../editor/util";
import {exitSiYuan} from "../dialog/processSystem";
import {isWindow} from "../util/functions";
import {initStatus} from "../layout/status";
@@ -23,14 +23,13 @@ import {replaceLocalPath} from "../editor/rename";
import {setTabPosition} from "../window/setHeader";
import {initBar} from "../layout/topBar";
import {openChangelog} from "./openChangelog";
-import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
import {App} from "../index";
import {initWindowEvent} from "./globalEvent/event";
import {sendGlobalShortcut} from "./globalEvent/keydown";
import {closeWindow} from "../window/closeWin";
-import {checkFold} from "../util/noRelyPCFunction";
import {correctHotkey} from "./globalEvent/commonHotkey";
import {recordBeforeResizeTop} from "../protyle/util/resize";
+import {processSYLink} from "../editor/openLink";
export const onGetConfig = (isStart: boolean, app: App) => {
correctHotkey(app);
@@ -173,75 +172,7 @@ export const initWindow = async (app: App) => {
});
if (!isWindow()) {
ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => {
- let urlObj: URL;
- try {
- urlObj = new URL(url);
- if (urlObj.protocol !== "siyuan:") {
- return;
- }
- } catch (error) {
- return;
- }
- if (urlObj && urlObj.hostname === "plugins") {
- const pluginNameType = urlObj.pathname.split("/")[1];
- if (!pluginNameType) {
- return;
- }
- app.plugins.find(plugin => {
- if (pluginNameType.startsWith(plugin.name)) {
- // siyuan://plugins/plugin-name/foo?bar=baz
- plugin.eventBus.emit("open-siyuan-url-plugin", {url});
-
- // https://github.com/siyuan-note/siyuan/pull/9256
- if (pluginNameType.split("/")[0] !== plugin.name) {
- // siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
- let data = urlObj.searchParams.get("data");
- try {
- data = JSON.parse(data || "{}");
- } catch (e) {
- console.log("Error open plugin tab with protocol:", e);
- }
- openFile({
- app,
- custom: {
- title: urlObj.searchParams.get("title"),
- icon: urlObj.searchParams.get("icon"),
- data,
- id: pluginNameType
- },
- });
- }
- return true;
- }
- });
- return;
- }
- if (urlObj && isSYProtocol(url)) {
- const id = getIdFromSYProtocol(url);
- const focus = urlObj.searchParams.get("focus") === "1";
- fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
- if (existResponse.data) {
- checkFold(id, (zoomIn) => {
- openFileById({
- app,
- id,
- action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
- zoomIn: zoomIn || focus
- });
- });
- ipcRenderer.send(Constants.SIYUAN_CMD, "show");
- }
- app.plugins.forEach(plugin => {
- plugin.eventBus.emit("open-siyuan-url-block", {
- url,
- id,
- focus,
- exist: existResponse.data,
- });
- });
- });
- return;
- }
+ processSYLink(app, url);
});
}
ipcRenderer.on(Constants.SIYUAN_OPEN_FILE, (event, data) => {
diff --git a/app/src/editor/openLink.ts b/app/src/editor/openLink.ts
index fc9858a31d..6f36f0e88e 100644
--- a/app/src/editor/openLink.ts
+++ b/app/src/editor/openLink.ts
@@ -1,12 +1,99 @@
-import {isLocalPath, pathPosix} from "../util/pathName";
+import {getIdFromSYProtocol, isLocalPath, isSYProtocol, pathPosix} from "../util/pathName";
/// #if !BROWSER
-import {shell} from "electron";
+import {shell, ipcRenderer} from "electron";
/// #endif
import {getSearch} from "../util/functions";
import {openByMobile} from "../protyle/util/compatibility";
import {Constants} from "../constants";
import {showMessage} from "../dialog/message";
-import {openAsset, openBy} from "./util";
+/// #if !MOBILE
+import {openAsset, openBy, openFile, openFileById} from "./util";
+/// #endif
+import {App} from "../index";
+import {fetchPost} from "../util/fetch";
+import {checkFold} from "../util/noRelyPCFunction";
+import {openMobileFileById} from "../mobile/editor";
+
+export const processSYLink = (app: App, url: string) => {
+ let urlObj: URL;
+ try {
+ urlObj = new URL(url);
+ if (urlObj.protocol !== "siyuan:") {
+ return false;
+ }
+ } catch (error) {
+ return false;
+ }
+ if (urlObj && urlObj.hostname === "plugins") {
+ const pluginNameType = urlObj.pathname.split("/")[1];
+ if (!pluginNameType) {
+ return false;
+ }
+ app.plugins.find(plugin => {
+ if (pluginNameType.startsWith(plugin.name)) {
+ // siyuan://plugins/plugin-name/foo?bar=baz
+ plugin.eventBus.emit("open-siyuan-url-plugin", {url});
+
+ /// #if !MOBILE
+ // https://github.com/siyuan-note/siyuan/pull/9256
+ if (pluginNameType.split("/")[0] !== plugin.name) {
+ // siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
+ let data = urlObj.searchParams.get("data");
+ try {
+ data = JSON.parse(data || "{}");
+ } catch (e) {
+ console.log("Error open plugin tab with protocol:", e);
+ }
+ openFile({
+ app,
+ custom: {
+ title: urlObj.searchParams.get("title"),
+ icon: urlObj.searchParams.get("icon"),
+ data,
+ id: pluginNameType
+ },
+ });
+ }
+ /// #endif
+ return true;
+ }
+ });
+ return true;
+ }
+ if (urlObj && isSYProtocol(url)) {
+ const id = getIdFromSYProtocol(url);
+ const focus = urlObj.searchParams.get("focus") === "1";
+ fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
+ if (existResponse.data) {
+ checkFold(id, (zoomIn) => {
+ /// #if !MOBILE
+ openFileById({
+ app,
+ id,
+ action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
+ zoomIn: zoomIn || focus
+ });
+ /// #else
+ openMobileFileById(app, id, (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
+ /// #endif
+ });
+ /// #if !BROWSER
+ ipcRenderer.send(Constants.SIYUAN_CMD, "show");
+ /// #endif
+ }
+ app.plugins.forEach(plugin => {
+ plugin.eventBus.emit("open-siyuan-url-block", {
+ url,
+ id,
+ focus,
+ exist: existResponse.data,
+ });
+ });
+ });
+ return true;
+ }
+ return false;
+};
export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
@@ -28,7 +115,7 @@ export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, c
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkAddress)) &&
(
!linkAddress.endsWith(".pdf") ||
- // 本地 pdf 仅 assets/ 开头的才使用 siyuan 打开
+ // 本地 pdf 仅 assets/ 开头的才使用 siyuan 打开
(linkAddress.endsWith(".pdf") && linkAddress.startsWith("assets/"))
)
) {
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 85591494a1..9b6879d754 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -3,6 +3,7 @@ import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {Constants} from "../../constants";
/// #if !BROWSER
import {clipboard, ipcRenderer} from "electron";
+import {processSYLink} from "../../editor/openLink";
/// #endif
export const encodeBase64 = (text: string): string => {
@@ -54,31 +55,8 @@ export const openByMobile = (uri: string) => {
return;
}
//https://github.com/siyuan-note/siyuan/issues/15892
- if (uri.startsWith("siyuan://")) {
- let urlObj: URL;
- try {
- urlObj = new URL(uri);
- if (urlObj.protocol !== "siyuan:") {
- return;
- }
- } catch (error) {
- return;
- }
- if (urlObj && urlObj.hostname === "plugins") {
- const pluginNameType = urlObj.pathname.split("/")[1];
- if (!pluginNameType) {
- return;
- }
- window.siyuan.ws.app.plugins.find((plugin) => {
- if (pluginNameType.startsWith(plugin.name)) {
- // siyuan://plugins/plugin-name/foo?bar=baz
- plugin.eventBus.emit("open-siyuan-url-plugin", {
- url: uri
- });
- }
- });
- return;
- }
+ if (processSYLink(window.siyuan.ws.app, uri)) {
+ return;
}
if (isInIOS()) {
if (uri.startsWith("assets/")) {
@@ -369,7 +347,7 @@ export const updateHotkeyTip = (hotkey: string) => {
const keys = [];
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push("Ctrl");
if (hotkey.indexOf("⇧") > -1) keys.push("Shift");
- if (hotkey.indexOf("⌥") > -1) keys.push( "Alt");
+ if (hotkey.indexOf("⌥") > -1) keys.push("Alt");
// 不能去最后一个,需匹配 F2
const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");