From 90372168b45fd6b9cbd25820c00ea149bebe6ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 13 Mar 2024 20:15:16 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=89=93=E5=BC=80=E5=90=8C=E4=B8=80=E4=B8=AA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BC=9A=E6=89=93=E5=BC=80=E5=A4=9A=E4=B8=AA=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E7=AA=97=E5=8F=A3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/electron/fileHandle.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web/src/electron/fileHandle.js b/web/src/electron/fileHandle.js index f6d9bbed..a3b96fc6 100644 --- a/web/src/electron/fileHandle.js +++ b/web/src/electron/fileHandle.js @@ -20,6 +20,7 @@ export const bindFileHandleEvent = ({ mainWindow }) => { // 新建编辑页面 const openIds = [] + const openIdToWin = {} const createEditWindow = async (event, id) => { openIds.push(id) const win = new BrowserWindow({ @@ -35,11 +36,13 @@ export const bindFileHandleEvent = ({ mainWindow }) => { preload: path.join(__dirname, 'preload.js') } }) + openIdToWin[id] = win win.on('closed', () => { // 从openIds数组中删除 - let index = openIds.find(item => { + const index = openIds.findIndex(item => { return item === id }) + delete openIdToWin[id] if (index !== -1) { openIds.splice(index, 1) } @@ -93,6 +96,17 @@ export const bindFileHandleEvent = ({ mainWindow }) => { }) return '文件不存在' } + // 检查该文件是否已经打开 + const existId = Object.keys(idToFilePath).find(item => { + return idToFilePath[item] === file + }) + if (openIds.includes(existId)) { + // 将已打开的窗口移至顶端 + if (openIdToWin[existId]) { + openIdToWin[existId].moveTop() + } + return + } let id = uuid() idToFilePath[id] = file saveToRecent(file).then(() => {