Skip to content

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

:bug: Dispatch mobile system plugin and marketplace links https://github.com/siyuan-note/siyuan/issues/20131

Daniel9db418133416
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 30102e05fb..16eb2af1f9 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -26,6 +26,7 @@ import {
} from "./util/touch";
import {fetchPost} from "../util/fetch";
import {initFramework} from "./util/initFramework";
+import {finishMobileSystemUris, processMobileSystemUri} from "./util/systemUri";
import {saveMobileLayout} from "./util/saveLayout";
import {finishMobileStartup} from "./util/setEmpty";
import {initAssets} from "../util/assets";
@@ -250,6 +251,7 @@ class App {
initRightMenu(this);
openChangelog();
window.siyuan.isReady = true;
+ finishMobileSystemUris(this);
mainWs.flushMainMessages();
fetchPost("/api/setting/getCloudUser", {});
} catch (error) {
@@ -352,5 +354,5 @@ window.openFileByURL = (openURL) => {
blockInfo.avItemID ? undefined : "start", undefined, blockInfo.avItemID ? (protyle) => activateQueuedAVLocate(protyle, blockInfo.id) : undefined);
return true;
}
- return false;
+ return processMobileSystemUri(siyuanApp, openURL);
};
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index 2b44efdfa5..cf6e80c4f1 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -10,7 +10,8 @@ import {fetchPost} from "../../util/fetch";
import {setInlineStyle} from "../../util/assets";
import {renderSnippet} from "../../config/util/snippets";
import {finishMobileStartup, setEmpty} from "./setEmpty";
-import {getOpenNotebookCount, parseUriInfo} from "../../util/pathName";
+import {getOpenNotebookCount, parseSiYuanUriInfo, parseUriInfo} from "../../util/pathName";
+import {processMobileSystemUri} from "./systemUri";
import {popMenu} from "../menu";
import {MobileFiles} from "../dock/MobileFiles";
import {MobileOutline} from "../dock/MobileOutline";
@@ -370,8 +371,10 @@ export const initFramework = async (app: App, isStart: boolean) => {
} else {
await window.siyuan.mobile.tabs.removeMissingTabs();
}
+ const systemURL = window.JSAndroid?.getBlockURL() || new URLSearchParams(window.location.search).get("url");
+ processMobileSystemUri(app, systemURL);
if (getOpenNotebookCount() > 0) {
- if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {
+ if (window.JSAndroid && parseSiYuanUriInfo(systemURL) && window.openFileByURL(systemURL)) {
return;
}
const info = parseUriInfo();
diff --git a/app/src/mobile/util/systemUri.ts b/app/src/mobile/util/systemUri.ts
new file mode 100644
index 0000000000..3625306e7c
--- /dev/null
+++ b/app/src/mobile/util/systemUri.ts
@@ -0,0 +1,29 @@
+import type {App} from "../../index";
+import {processSiYuanUri} from "../../util/uri";
+
+let ready = false;
+const pending = new Set<string>();
+
+// 系统链接在插件、语言和移动端界面就绪后分派,块链接继续使用移动端的定位流程。
+export const processMobileSystemUri = (app: App, uri: string) => {
+ try {
+ const url = new URL(uri);
+ if (url.protocol !== "siyuan:" || !["plugins", "bazaar"].includes(url.hostname)) {
+ return false;
+ }
+ } catch {
+ return false;
+ }
+ if (!ready) {
+ pending.add(uri);
+ return true;
+ }
+ return processSiYuanUri(app, uri);
+};
+
+export const finishMobileSystemUris = (app: App) => {
+ ready = true;
+ const uris = [...pending];
+ pending.clear();
+ uris.forEach(uri => processSiYuanUri(app, uri));
+};
diff --git a/app/tests/mobileSystemUri.test.js b/app/tests/mobileSystemUri.test.js
new file mode 100644
index 0000000000..acfd5ff571
--- /dev/null
+++ b/app/tests/mobileSystemUri.test.js
@@ -0,0 +1,33 @@
+const assert = require("node:assert/strict");
+const {readFileSync} = require("node:fs");
+const path = require("node:path");
+const {test} = require("node:test");
+const ts = require("typescript");
+
+test("mobile system links wait for startup and use the shared URI dispatcher", () => {
+ const source = readFileSync(path.join(__dirname, "../src/mobile/util/systemUri.ts"), "utf8");
+ const code = ts.transpileModule(source, {compilerOptions: {
+ module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022,
+ }}).outputText;
+ const calls = [];
+ const app = {};
+ const api = {};
+ new Function("exports", "require", code)(api, () => ({
+ processSiYuanUri: (...args) => { calls.push(args); return true; },
+ }));
+ const plugin = "siyuan://plugins/demo/install?repo=owner/repo&tag=v1.0.0";
+ const bazaar = "siyuan://bazaar/plugins/demo/readme";
+ assert.equal(api.processMobileSystemUri(app, plugin), true);
+ assert.equal(api.processMobileSystemUri(app, plugin), true);
+ assert.equal(api.processMobileSystemUri(app, bazaar), true);
+ for (const uri of [null, "invalid", "https://plugins/demo", "siyuan://blocks/20261006120000-abcdefg"]) {
+ assert.equal(api.processMobileSystemUri(app, uri), false);
+ }
+ assert.equal(calls.length, 0);
+ api.finishMobileSystemUris(app);
+ assert.deepEqual(calls, [[app, plugin], [app, bazaar]]);
+ api.finishMobileSystemUris(app);
+ assert.equal(calls.length, 2);
+ assert.equal(api.processMobileSystemUri(app, plugin), true);
+ assert.deepEqual(calls[2], [app, plugin]);
+});