mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
This commit is contained in:
parent
7c653d3689
commit
a18e3a585c
9 changed files with 44 additions and 46 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import {BlockPanel} from "./Panel";
|
||||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {fetchSyncPost} from "../util/fetch";
|
||||
import {getIdFromSiyuanUrl} from "../util/functions";
|
||||
import {hideTooltip, showTooltip} from "../dialog/tooltip";
|
||||
import {getIdFromSYProtocol} from "../util/pathName";
|
||||
|
||||
let popoverTargetElement: HTMLElement;
|
||||
export const initBlockPopover = () => {
|
||||
|
|
@ -200,7 +200,7 @@ export const showPopover = async () => {
|
|||
}
|
||||
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
|
||||
// 以思源协议开头的链接
|
||||
ids = [getIdFromSiyuanUrl(popoverTargetElement.getAttribute("data-href"))];
|
||||
ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))];
|
||||
} else {
|
||||
// pdf
|
||||
let targetId;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {renderSnippet} from "../config/util/snippets";
|
|||
import {openFileById} from "../editor/util";
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {exitSiYuan} from "../dialog/processSystem";
|
||||
import {getSearch, isWindow, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
|
||||
import {getSearch, isWindow} from "../util/functions";
|
||||
import {initStatus} from "../layout/status";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {replaceLocalPath} from "../editor/rename";
|
||||
|
|
@ -25,6 +25,7 @@ import {setTabPosition} from "../window/setHeader";
|
|||
import {initBar} from "../layout/topBar";
|
||||
import {setProxy} from "../config/util/setProxy";
|
||||
import {openChangelog} from "./openChangelog";
|
||||
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||
|
||||
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
||||
if (key1 === "general") {
|
||||
|
|
@ -212,10 +213,10 @@ export const initWindow = () => {
|
|||
});
|
||||
if (!isWindow()) {
|
||||
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
|
||||
if (!isSiyuanUrl(url)) {
|
||||
if (!isSYProtocol(url)) {
|
||||
return;
|
||||
}
|
||||
const id = getIdFromSiyuanUrl(url);
|
||||
const id = getIdFromSYProtocol(url);
|
||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||
if (existResponse.data) {
|
||||
openFileById({
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ import {getCurrentWindow} from "@electron/remote";
|
|||
/// #endif
|
||||
import {hideMessage, showMessage} from "./message";
|
||||
import {Dialog} from "./index";
|
||||
import {isMobile, redirectToCheckAuth} from "../util/functions";
|
||||
import {isMobile} from "../util/functions";
|
||||
import {confirmDialog} from "./confirmDialog";
|
||||
import {escapeHtml} from "../util/escape";
|
||||
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
||||
import {needSubscribe} from "../util/needSubscribe";
|
||||
import { redirectToCheckAuth } from "../util/pathName";
|
||||
|
||||
export const lockScreen = () => {
|
||||
if (window.siyuan.config.readonly) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {account} from "./config/account";
|
|||
import {addScript, addScriptSync} from "./protyle/util/addScript";
|
||||
import {genUUID} from "./util/genID";
|
||||
import {fetchGet, fetchPost} from "./util/fetch";
|
||||
import {addBaseURL, setNoteBook} from "./util/pathName";
|
||||
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "./util/pathName";
|
||||
import {registerServiceWorker} from "./util/serviceWorker";
|
||||
import {openFileById} from "./editor/util";
|
||||
import {
|
||||
|
|
@ -27,12 +27,13 @@ import {resizeDrag} from "./layout/util";
|
|||
import {getAllTabs} from "./layout/getAll";
|
||||
import {getLocalStorage} from "./protyle/util/compatibility";
|
||||
import {updateEditModeElement} from "./layout/topBar";
|
||||
import {getIdFromSiyuanUrl, getSearch, isSiyuanUrl} from "./util/functions";
|
||||
import {getSearch} from "./util/functions";
|
||||
import {hideAllElements} from "./protyle/ui/hideElements";
|
||||
import {initPluginSystem} from 'siyuan-petal';
|
||||
|
||||
class App {
|
||||
constructor() {
|
||||
// TODO
|
||||
/// #if BROWSER
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
/// #endif
|
||||
|
|
@ -183,9 +184,9 @@ class App {
|
|||
|
||||
new App();
|
||||
window.openFileByURL = (openURL) => {
|
||||
if (openURL && isSiyuanUrl(openURL)) {
|
||||
if (openURL && isSYProtocol(openURL)) {
|
||||
openFileById({
|
||||
id: getIdFromSiyuanUrl(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]
|
||||
});
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -27,11 +27,12 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
|
|||
import {pdfResize} from "../asset/renderAssets";
|
||||
import {Backlink} from "./dock/Backlink";
|
||||
import {openFileById} from "../editor/util";
|
||||
import {getSearch, isWindow, isSiyuanUrl, isWebSiyuanUrl, getIdFromSiyuanUrl, getIdFromWebSiyuanUrl} from "../util/functions";
|
||||
import {getSearch, isWindow} from "../util/functions";
|
||||
/// #if !BROWSER
|
||||
import {setTabPosition} from "../window/setHeader";
|
||||
/// #endif
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||
|
||||
export const setPanelFocus = (element: Element) => {
|
||||
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
|
||||
|
|
@ -369,17 +370,19 @@ export const JSONToLayout = (isStart: boolean) => {
|
|||
});
|
||||
}
|
||||
|
||||
// PWA 捕获 siyuan://
|
||||
// TODO PWA 捕获 siyuan://
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const url = searchParams.get("url");
|
||||
if (isSiyuanUrl(url) || isWebSiyuanUrl(url)) {
|
||||
|
||||
const isWebSiyuanUrl = /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
if (isSYProtocol(url) || isWebSiyuanUrl) {
|
||||
searchParams.delete("url");
|
||||
switch (true) {
|
||||
case isSiyuanUrl(url):
|
||||
searchParams.set("id", getIdFromSiyuanUrl(url));
|
||||
case isSYProtocol(url):
|
||||
searchParams.set("id", getIdFromSYProtocol(url));
|
||||
break;
|
||||
case isWebSiyuanUrl(url):
|
||||
searchParams.set("id", getIdFromWebSiyuanUrl(url));
|
||||
case isWebSiyuanUrl:
|
||||
searchParams.set("id", url.substring(20, 20 + 22));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
|||
import {Model} from "../layout/Model";
|
||||
import "../assets/scss/mobile.scss";
|
||||
import {Menus} from "../menus";
|
||||
import {addBaseURL, setNoteBook} from "../util/pathName";
|
||||
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";
|
||||
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
|
||||
import {fetchGet, fetchPost} from "../util/fetch";
|
||||
import {initFramework} from "./util/initFramework";
|
||||
|
|
@ -18,7 +18,7 @@ import {goBack} from "./util/MobileBackFoward";
|
|||
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
|
||||
import {getLocalStorage} from "../protyle/util/compatibility";
|
||||
import {openMobileFileById} from "./editor";
|
||||
import {getSearch, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
|
||||
import {getSearch} from "../util/functions";
|
||||
import {initRightMenu} from "./menu";
|
||||
import {openChangelog} from "../boot/openChangelog";
|
||||
|
||||
|
|
@ -90,8 +90,8 @@ window.showKeyboardToolbar = (height) => {
|
|||
};
|
||||
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
||||
window.openFileByURL = (openURL) => {
|
||||
if (openURL && isSiyuanUrl(openURL)) {
|
||||
openMobileFileById(getIdFromSiyuanUrl(openURL),
|
||||
if (openURL && isSYProtocol(openURL)) {
|
||||
openMobileFileById(getIdFromSYProtocol(openURL),
|
||||
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,27 +46,3 @@ export const isFileAnnotation = (text: string) => {
|
|||
export const looseJsonParse = (text: string) => {
|
||||
return Function(`"use strict";return (${text})`)();
|
||||
};
|
||||
|
||||
/* redirect to auth page */
|
||||
export const redirectToCheckAuth = (to: string = window.location.href) => {
|
||||
const url = new URL(window.location.origin);
|
||||
url.pathname = '/check-auth';
|
||||
url.searchParams.set('to', to);
|
||||
window.location.href = url.href;
|
||||
}
|
||||
|
||||
export const isSiyuanUrl = (url: string) => {
|
||||
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
}
|
||||
|
||||
export const isWebSiyuanUrl = (url: string) => {
|
||||
return /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
}
|
||||
|
||||
export const getIdFromSiyuanUrl = (url: string) => {
|
||||
return url.substring(16, 16 + 22);
|
||||
}
|
||||
|
||||
export const getIdFromWebSiyuanUrl = (url: string) => {
|
||||
return url.substring(20, 20 + 22);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,22 @@ import {unicode2Emoji} from "../emoji";
|
|||
import {Constants} from "../constants";
|
||||
import {showMessage} from "../dialog/message";
|
||||
|
||||
export const isSYProtocol = (url: string) => {
|
||||
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
}
|
||||
|
||||
export const getIdFromSYProtocol = (url: string) => {
|
||||
return url.substring(16, 16 + 22);
|
||||
}
|
||||
|
||||
/* redirect to auth page */
|
||||
export const redirectToCheckAuth = (to: string = window.location.href) => {
|
||||
const url = new URL(window.location.origin);
|
||||
url.pathname = '/check-auth';
|
||||
url.searchParams.set('to', to);
|
||||
window.location.href = url.href;
|
||||
}
|
||||
|
||||
export const addBaseURL = () => {
|
||||
let baseURLElement = document.getElementById("baseURL");
|
||||
if (!baseURLElement) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {exportLayout, getInstanceById} from "../layout/util";
|
||||
import {Tab} from "../layout/Tab";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
import {redirectToCheckAuth} from "../util/functions";
|
||||
import {redirectToCheckAuth} from "../util/pathName";
|
||||
|
||||
const closeTab = (ipcData: IWebSocketData) => {
|
||||
const tab = getInstanceById(ipcData.data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue