mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
This commit is contained in:
parent
11786381cf
commit
449d2dbf87
@ -15,7 +15,7 @@ import {renderSnippet} from "../config/util/snippets";
|
|||||||
import {openFile, 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, trimPrefix} from "../util/functions";
|
import {isWindow} from "../util/functions";
|
||||||
import {initStatus} from "../layout/status";
|
import {initStatus} from "../layout/status";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {replaceLocalPath} from "../editor/rename";
|
import {replaceLocalPath} from "../editor/rename";
|
||||||
@ -247,27 +247,27 @@ 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;
|
||||||
try {
|
try {
|
||||||
var urlObj = new URL(url);
|
urlObj = new URL(url);
|
||||||
if (urlObj.protocol !== "siyuan:") {
|
if (urlObj.protocol !== "siyuan:") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (urlObj.pathname.startsWith("//plugins/")) {
|
if (urlObj && urlObj.pathname.startsWith("//plugins/")) {
|
||||||
const pluginPathname = trimPrefix(urlObj.pathname, "//plugins/");
|
const pluginNameType = urlObj.pathname.replace("//plugins/", "");
|
||||||
if (!pluginPathname) {
|
if (!pluginNameType) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pluginId = pluginPathname.split("/")[0];
|
app.plugins.find(plugin => {
|
||||||
app.plugins.forEach(plugin => {
|
if (pluginNameType.startsWith(plugin.name)) {
|
||||||
if (pluginPathname.startsWith(plugin.name)) {
|
|
||||||
// siyuan://plugins/plugin-name/foo?bar=baz
|
// siyuan://plugins/plugin-name/foo?bar=baz
|
||||||
plugin.eventBus.emit("open-siyuan-url-plugin", {url});
|
plugin.eventBus.emit("open-siyuan-url-plugin", {url});
|
||||||
|
|
||||||
// https://github.com/siyuan-note/siyuan/pull/9256
|
// https://github.com/siyuan-note/siyuan/pull/9256
|
||||||
if (pluginId !== plugin.name) {
|
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."}
|
// 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");
|
let data = urlObj.searchParams.get("data");
|
||||||
try {
|
try {
|
||||||
@ -281,15 +281,16 @@ export const initWindow = async (app: App) => {
|
|||||||
title: urlObj.searchParams.get("title"),
|
title: urlObj.searchParams.get("title"),
|
||||||
icon: urlObj.searchParams.get("icon"),
|
icon: urlObj.searchParams.get("icon"),
|
||||||
data,
|
data,
|
||||||
id: pluginPathname
|
id: pluginNameType
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isSYProtocol(url)) {
|
if (urlObj && isSYProtocol(url)) {
|
||||||
const id = getIdFromSYProtocol(url);
|
const id = getIdFromSYProtocol(url);
|
||||||
const focus = urlObj.searchParams.get("focus") === "1";
|
const focus = urlObj.searchParams.get("focus") === "1";
|
||||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||||
|
@ -90,11 +90,3 @@ export const objEquals = (a: any, b: any): boolean => {
|
|||||||
if (keys.length !== Object.keys(b).length) return false;
|
if (keys.length !== Object.keys(b).length) return false;
|
||||||
return keys.every(k => objEquals(a[k], b[k]));
|
return keys.every(k => objEquals(a[k], b[k]));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const trimPrefix = (str: string, prefix: string) => {
|
|
||||||
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const trimSuffix = (str: string, suffix: string) => {
|
|
||||||
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user