Vanessa 2023-04-19 18:50:15 +08:00
parent f8025cb7e6
commit d76180796c
5 changed files with 40 additions and 40 deletions

View file

@ -136,9 +136,6 @@ export const onGetConfig = (isStart: boolean) => {
try { try {
JSONToLayout(isStart); JSONToLayout(isStart);
openChangelog(); openChangelog();
if (window.JSAndroid) {
window.openFileByURL(window.JSAndroid.getBlockURL());
}
} catch (e) { } catch (e) {
resetLayout(); resetLayout();
} }

View file

@ -178,11 +178,14 @@ class App {
} }
new App(); new App();
window.openFileByURL = (openURL) => { window.openFileByURL = (openURL) => {
if (openURL && isSYProtocol(openURL)) { if (openURL && isSYProtocol(openURL)) {
const isZoomIn = getSearch("focus", openURL) === "1"
openFileById({ openFileById({
id: getIdFromSYProtocol(openURL), id: getIdFromSYProtocol(openURL),
action: getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT] action: isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: isZoomIn
}); });
return true; return true;
} }

View file

@ -32,7 +32,7 @@ import {getSearch, isWindow} from "../util/functions";
import {setTabPosition} from "../window/setHeader"; import {setTabPosition} from "../window/setHeader";
/// #endif /// #endif
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName"; import {getIdZoomInByPath} from "../util/pathName";
export const setPanelFocus = (element: Element) => { export const setPanelFocus = (element: Element) => {
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) { if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
@ -369,38 +369,15 @@ export const JSONToLayout = (isStart: boolean) => {
} }
}); });
} }
const idZoomIn = getIdZoomInByPath();
// TODO PWA 捕获 siyuan://
const searchParams = new URLSearchParams(window.location.search);
const url = searchParams.get("url");
const isWebSiyuanUrl = /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
if (isSYProtocol(url) || isWebSiyuanUrl) {
searchParams.delete("url");
switch (true) {
case isSYProtocol(url):
searchParams.set("id", getIdFromSYProtocol(url));
break;
case isWebSiyuanUrl:
searchParams.set("id", url.substring(20, 20 + 22));
break;
}
const focus = getSearch("focus", url);
if (focus) {
searchParams.set("focus", focus);
}
}
// 支持通过 URL 查询字符串参数 `id` 和 `focus` 跳转到 Web 端指定块 https://github.com/siyuan-note/siyuan/pull/7086
const openId = searchParams.get("id");
if (openId) {
// 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟 // 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟
if (idZoomIn.id) {
setTimeout(() => { setTimeout(() => {
openFileById({ openFileById({
id: openId, id: idZoomIn.id,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: searchParams.get("focus") === "1" zoomIn: idZoomIn.isZoomIn
}); });
}, Constants.TIMEOUT_BLOCKLOAD); }, Constants.TIMEOUT_BLOCKLOAD);
} }

View file

@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";
import {setInlineStyle} from "../../util/assets"; import {setInlineStyle} from "../../util/assets";
import {renderSnippet} from "../../config/util/snippets"; import {renderSnippet} from "../../config/util/snippets";
import {setEmpty} from "./setEmpty"; import {setEmpty} from "./setEmpty";
import {getOpenNotebookCount} from "../../util/pathName"; import {getIdZoomInByPath, getOpenNotebookCount} from "../../util/pathName";
import {popMenu} from "../menu"; import {popMenu} from "../menu";
import {MobileFiles} from "./MobileFiles"; import {MobileFiles} from "./MobileFiles";
import {MobileOutline} from "./MobileOutline"; import {MobileOutline} from "./MobileOutline";
@ -140,10 +140,10 @@ export const initFramework = () => {
if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) { if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {
return; return;
} }
const openId = getSearch("id"); const idZoomIn = getIdZoomInByPath();
if (openId) { if (idZoomIn.id) {
openMobileFileById(openId, openMobileFileById(idZoomIn.id,
getSearch("focus") === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]); idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
return; return;
} }
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO]; const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];

View file

@ -2,12 +2,35 @@ import * as path from "path";
import {fetchPost} from "./fetch"; import {fetchPost} from "./fetch";
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {escapeHtml} from "./escape"; import {escapeHtml} from "./escape";
import {isMobile} from "./functions"; import {getSearch, isMobile} from "./functions";
import {focusByRange} from "../protyle/util/selection"; import {focusByRange} from "../protyle/util/selection";
import {unicode2Emoji} from "../emoji"; import {unicode2Emoji} from "../emoji";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
export const getIdZoomInByPath = () => {
const searchParams = new URLSearchParams(window.location.search);
const PWAURL = searchParams.get("url");
let id = "";
let isZoomIn = false;
if (/^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(PWAURL)) {
// PWA 捕获 web+siyuan://blocks/20221031001313-rk7sd0e?focus=1
id = PWAURL.substring(20, 20 + 22)
isZoomIn = getSearch("focus", PWAURL) === "1";
} else if (window.JSAndroid) {
// PAD 通过思源协议打开
const SYURL = window.JSAndroid.getBlockURL();
id = getIdFromSYProtocol(SYURL);
isZoomIn = getSearch("focus", SYURL) === "1"
} else {
// 支持通过 URL 查询字符串参数 `id` 和 `focus` 跳转到 Web 端指定块 https://github.com/siyuan-note/siyuan/pull/7086
id = searchParams.get("id");
isZoomIn = searchParams.get("focus") === "1";
}
return {
id, isZoomIn
}
}
export const isSYProtocol = (url: string) => { export const isSYProtocol = (url: string) => {
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url); return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
}; };