mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
This commit is contained in:
parent
348950ab51
commit
341ef4ed4c
3 changed files with 98 additions and 102 deletions
|
|
@ -14,7 +14,7 @@ import {appearance} from "../config/appearance";
|
||||||
import {fetchPost, fetchSyncPost} from "../util/fetch";
|
import {fetchPost, fetchSyncPost} from "../util/fetch";
|
||||||
import {initAssets, setInlineStyle} from "../util/assets";
|
import {initAssets, setInlineStyle} from "../util/assets";
|
||||||
import {renderSnippet} from "../config/util/snippets";
|
import {renderSnippet} from "../config/util/snippets";
|
||||||
import {openFile, openFileById} from "../editor/util";
|
import {openFile} from "../editor/util";
|
||||||
import {exitSiYuan} from "../dialog/processSystem";
|
import {exitSiYuan} from "../dialog/processSystem";
|
||||||
import {isWindow} from "../util/functions";
|
import {isWindow} from "../util/functions";
|
||||||
import {initStatus} from "../layout/status";
|
import {initStatus} from "../layout/status";
|
||||||
|
|
@ -23,14 +23,13 @@ import {replaceLocalPath} from "../editor/rename";
|
||||||
import {setTabPosition} from "../window/setHeader";
|
import {setTabPosition} from "../window/setHeader";
|
||||||
import {initBar} from "../layout/topBar";
|
import {initBar} from "../layout/topBar";
|
||||||
import {openChangelog} from "./openChangelog";
|
import {openChangelog} from "./openChangelog";
|
||||||
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {initWindowEvent} from "./globalEvent/event";
|
import {initWindowEvent} from "./globalEvent/event";
|
||||||
import {sendGlobalShortcut} from "./globalEvent/keydown";
|
import {sendGlobalShortcut} from "./globalEvent/keydown";
|
||||||
import {closeWindow} from "../window/closeWin";
|
import {closeWindow} from "../window/closeWin";
|
||||||
import {checkFold} from "../util/noRelyPCFunction";
|
|
||||||
import {correctHotkey} from "./globalEvent/commonHotkey";
|
import {correctHotkey} from "./globalEvent/commonHotkey";
|
||||||
import {recordBeforeResizeTop} from "../protyle/util/resize";
|
import {recordBeforeResizeTop} from "../protyle/util/resize";
|
||||||
|
import {processSYLink} from "../editor/openLink";
|
||||||
|
|
||||||
export const onGetConfig = (isStart: boolean, app: App) => {
|
export const onGetConfig = (isStart: boolean, app: App) => {
|
||||||
correctHotkey(app);
|
correctHotkey(app);
|
||||||
|
|
@ -173,75 +172,7 @@ export const initWindow = async (app: App) => {
|
||||||
});
|
});
|
||||||
if (!isWindow()) {
|
if (!isWindow()) {
|
||||||
ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => {
|
ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => {
|
||||||
let urlObj: URL;
|
processSYLink(app, 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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ipcRenderer.on(Constants.SIYUAN_OPEN_FILE, (event, data) => {
|
ipcRenderer.on(Constants.SIYUAN_OPEN_FILE, (event, data) => {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,99 @@
|
||||||
import {isLocalPath, pathPosix} from "../util/pathName";
|
import {getIdFromSYProtocol, isLocalPath, isSYProtocol, pathPosix} from "../util/pathName";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {shell} from "electron";
|
import {shell, ipcRenderer} from "electron";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {getSearch} from "../util/functions";
|
import {getSearch} from "../util/functions";
|
||||||
import {openByMobile} from "../protyle/util/compatibility";
|
import {openByMobile} from "../protyle/util/compatibility";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {showMessage} from "../dialog/message";
|
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) => {
|
export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
|
||||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
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)) &&
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkAddress)) &&
|
||||||
(
|
(
|
||||||
!linkAddress.endsWith(".pdf") ||
|
!linkAddress.endsWith(".pdf") ||
|
||||||
// 本地 pdf 仅 assets/ 开头的才使用 siyuan 打开
|
// 本地 pdf 仅 assets/ 开头的才使用 siyuan 打开
|
||||||
(linkAddress.endsWith(".pdf") && linkAddress.startsWith("assets/"))
|
(linkAddress.endsWith(".pdf") && linkAddress.startsWith("assets/"))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {clipboard, ipcRenderer} from "electron";
|
import {clipboard, ipcRenderer} from "electron";
|
||||||
|
import {processSYLink} from "../../editor/openLink";
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
||||||
export const encodeBase64 = (text: string): string => {
|
export const encodeBase64 = (text: string): string => {
|
||||||
|
|
@ -54,31 +55,8 @@ export const openByMobile = (uri: string) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//https://github.com/siyuan-note/siyuan/issues/15892
|
//https://github.com/siyuan-note/siyuan/issues/15892
|
||||||
if (uri.startsWith("siyuan://")) {
|
if (processSYLink(window.siyuan.ws.app, uri)) {
|
||||||
let urlObj: URL;
|
return;
|
||||||
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 (isInIOS()) {
|
if (isInIOS()) {
|
||||||
if (uri.startsWith("assets/")) {
|
if (uri.startsWith("assets/")) {
|
||||||
|
|
@ -369,7 +347,7 @@ export const updateHotkeyTip = (hotkey: string) => {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push("Ctrl");
|
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push("Ctrl");
|
||||||
if (hotkey.indexOf("⇧") > -1) keys.push("Shift");
|
if (hotkey.indexOf("⇧") > -1) keys.push("Shift");
|
||||||
if (hotkey.indexOf("⌥") > -1) keys.push( "Alt");
|
if (hotkey.indexOf("⌥") > -1) keys.push("Alt");
|
||||||
|
|
||||||
// 不能去最后一个,需匹配 F2
|
// 不能去最后一个,需匹配 F2
|
||||||
const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");
|
const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue