This commit is contained in:
Vanessa 2023-06-15 23:36:06 +08:00
parent b38863df8a
commit 11f7960fd8
2 changed files with 45 additions and 14 deletions

View file

@ -14,7 +14,7 @@ import {globalShortcut} from "../boot/globalShortcut";
import {fetchPost, fetchSyncPost} from "../util/fetch"; import {fetchPost, fetchSyncPost} from "../util/fetch";
import {addGA, initAssets, setInlineStyle} from "../util/assets"; import {addGA, initAssets, setInlineStyle} from "../util/assets";
import {renderSnippet} from "../config/util/snippets"; import {renderSnippet} from "../config/util/snippets";
import {openFileById} from "../editor/util"; import {openFile, openFileById} from "../editor/util";
import {focusByRange} from "../protyle/util/selection"; import {focusByRange} from "../protyle/util/selection";
import {exitSiYuan} from "../dialog/processSystem"; import {exitSiYuan} from "../dialog/processSystem";
import {getSearch, isWindow} from "../util/functions"; import {getSearch, isWindow} from "../util/functions";
@ -249,9 +249,37 @@ export const initWindow = (app: App) => {
currentWindow.on("blur", winOnBlur); currentWindow.on("blur", winOnBlur);
if (!isWindow()) { if (!isWindow()) {
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => { 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; return;
} }
if (isSYProtocol(url)) {
const id = getIdFromSYProtocol(url); const id = getIdFromSYProtocol(url);
fetchPost("/api/block/checkBlockExist", {id}, existResponse => { fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
if (existResponse.data) { if (existResponse.data) {
@ -264,6 +292,8 @@ export const initWindow = (app: App) => {
ipcRenderer.send(Constants.SIYUAN_SHOW, getCurrentWindow().id); ipcRenderer.send(Constants.SIYUAN_SHOW, getCurrentWindow().id);
} }
}); });
return;
}
}); });
ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => { ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => {
winOnClose(currentWindow, close); winOnClose(currentWindow, close);

View file

@ -31,6 +31,7 @@ export const getIdZoomInByPath = () => {
id, isZoomIn 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);
}; };