diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 41319684f..0ba6023b5 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -14,6 +14,7 @@ import {focusBlock, focusByRange} from "../protyle/util/selection"; import {onGet} from "../protyle/util/onGet"; /// #if !BROWSER import {shell} from "electron"; +import {BrowserWindow} from "@electron/remote"; /// #endif import {pushBack} from "../util/backForward"; import {Asset} from "../asset"; @@ -23,6 +24,7 @@ import {setTitle} from "../dialog/processSystem"; import {zoomOut} from "../menus/protyle"; import {countBlockWord, countSelectWord} from "../layout/status"; import {showMessage} from "../dialog/message"; +import {getSearch} from "../util/functions"; export const openFileById = (options: { id: string, @@ -112,6 +114,26 @@ const openFile = (options: IOpenFileOptions) => { } } + let hasOpen = false; + /// #if !BROWSER + // https://github.com/siyuan-note/siyuan/issues/7491 + BrowserWindow.getAllWindows().find((item) => { + const json = getSearch("json", new URL(item.webContents.getURL()).search) + if (json) { + const jsonObj = JSON.parse(json); + if ((jsonObj.children.rootId && jsonObj.children.rootId === options.rootID) || + (jsonObj.children.path && jsonObj.children.path === options.assetPath)) { + item.focus(); + hasOpen = true; + return true; + } + } + }); + /// #endif + if (hasOpen) { + return; + } + let wnd: Wnd = undefined; // 获取光标所在 tab const element = document.querySelector(".layout__wnd--active");