mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
b38863df8a
commit
11f7960fd8
2 changed files with 45 additions and 14 deletions
|
|
@ -14,7 +14,7 @@ import {globalShortcut} from "../boot/globalShortcut";
|
|||
import {fetchPost, fetchSyncPost} from "../util/fetch";
|
||||
import {addGA, initAssets, setInlineStyle} from "../util/assets";
|
||||
import {renderSnippet} from "../config/util/snippets";
|
||||
import {openFileById} from "../editor/util";
|
||||
import {openFile, openFileById} from "../editor/util";
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {exitSiYuan} from "../dialog/processSystem";
|
||||
import {getSearch, isWindow} from "../util/functions";
|
||||
|
|
@ -249,9 +249,37 @@ export const initWindow = (app: App) => {
|
|||
currentWindow.on("blur", winOnBlur);
|
||||
if (!isWindow()) {
|
||||
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
|
||||
if (!isSYProtocol(url)) {
|
||||
if (/^siyuan:\/\/plugins\//.test(url)) {
|
||||
// siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
|
||||
const pluginId = url.replace("siyuan://plugins/", "").split("?")[0]
|
||||
app.plugins.find(plugin => {
|
||||
const match = Object.keys(plugin.models).find(key => {
|
||||
if (key === pluginId) {
|
||||
let data = getSearch("data", url)
|
||||
try {
|
||||
data = JSON.parse(data || "{}");
|
||||
} catch (e) {
|
||||
console.log("Error open plugin tab with protocol:", e)
|
||||
}
|
||||
openFile({
|
||||
app,
|
||||
custom: {
|
||||
title: getSearch("title", url),
|
||||
icon: getSearch("icon", url),
|
||||
data: JSON.parse(getSearch("data", url) || "{}"),
|
||||
fn: plugin.models[key]
|
||||
},
|
||||
});
|
||||
return true
|
||||
}
|
||||
})
|
||||
if (match) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (isSYProtocol(url)) {
|
||||
const id = getIdFromSYProtocol(url);
|
||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||
if (existResponse.data) {
|
||||
|
|
@ -264,6 +292,8 @@ export const initWindow = (app: App) => {
|
|||
ipcRenderer.send(Constants.SIYUAN_SHOW, getCurrentWindow().id);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => {
|
||||
winOnClose(currentWindow, close);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export const getIdZoomInByPath = () => {
|
|||
id, isZoomIn
|
||||
};
|
||||
};
|
||||
|
||||
export const isSYProtocol = (url: string) => {
|
||||
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue