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 {initAssets, setInlineStyle} from "../util/assets";
|
||||
import {renderSnippet} from "../config/util/snippets";
|
||||
import {openFile, openFileById} from "../editor/util";
|
||||
import {openFile} from "../editor/util";
|
||||
import {exitSiYuan} from "../dialog/processSystem";
|
||||
import {isWindow} from "../util/functions";
|
||||
import {initStatus} from "../layout/status";
|
||||
|
|
@ -23,14 +23,13 @@ import {replaceLocalPath} from "../editor/rename";
|
|||
import {setTabPosition} from "../window/setHeader";
|
||||
import {initBar} from "../layout/topBar";
|
||||
import {openChangelog} from "./openChangelog";
|
||||
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||
import {App} from "../index";
|
||||
import {initWindowEvent} from "./globalEvent/event";
|
||||
import {sendGlobalShortcut} from "./globalEvent/keydown";
|
||||
import {closeWindow} from "../window/closeWin";
|
||||
import {checkFold} from "../util/noRelyPCFunction";
|
||||
import {correctHotkey} from "./globalEvent/commonHotkey";
|
||||
import {recordBeforeResizeTop} from "../protyle/util/resize";
|
||||
import {processSYLink} from "../editor/openLink";
|
||||
|
||||
export const onGetConfig = (isStart: boolean, app: App) => {
|
||||
correctHotkey(app);
|
||||
|
|
@ -173,75 +172,7 @@ export const initWindow = async (app: App) => {
|
|||
});
|
||||
if (!isWindow()) {
|
||||
ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => {
|
||||
let urlObj: 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;
|
||||
}
|
||||
processSYLink(app, url);
|
||||
});
|
||||
}
|
||||
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
|
||||
import {shell} from "electron";
|
||||
import {shell, ipcRenderer} from "electron";
|
||||
/// #endif
|
||||
import {getSearch} from "../util/functions";
|
||||
import {openByMobile} from "../protyle/util/compatibility";
|
||||
import {Constants} from "../constants";
|
||||
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) => {
|
||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
|||
import {Constants} from "../../constants";
|
||||
/// #if !BROWSER
|
||||
import {clipboard, ipcRenderer} from "electron";
|
||||
import {processSYLink} from "../../editor/openLink";
|
||||
/// #endif
|
||||
|
||||
export const encodeBase64 = (text: string): string => {
|
||||
|
|
@ -54,32 +55,9 @@ export const openByMobile = (uri: string) => {
|
|||
return;
|
||||
}
|
||||
//https://github.com/siyuan-note/siyuan/issues/15892
|
||||
if (uri.startsWith("siyuan://")) {
|
||||
let urlObj: URL;
|
||||
try {
|
||||
urlObj = new URL(uri);
|
||||
if (urlObj.protocol !== "siyuan:") {
|
||||
if (processSYLink(window.siyuan.ws.app, uri)) {
|
||||
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 (uri.startsWith("assets/")) {
|
||||
// iOS 16.7 之前的版本,uri 需要 encodeURIComponent
|
||||
|
|
@ -369,7 +347,7 @@ export const updateHotkeyTip = (hotkey: string) => {
|
|||
const keys = [];
|
||||
if ((hotkey.indexOf("⌘") > -1 || hotkey.indexOf("⌃") > -1)) keys.push("Ctrl");
|
||||
if (hotkey.indexOf("⇧") > -1) keys.push("Shift");
|
||||
if (hotkey.indexOf("⌥") > -1) keys.push( "Alt");
|
||||
if (hotkey.indexOf("⌥") > -1) keys.push("Alt");
|
||||
|
||||
// 不能去最后一个,需匹配 F2
|
||||
const lastKey = hotkey.replace(/[⌘⇧⌥⌃]/g, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue