mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-23 11:27:41 +08:00
Fix:修复重复打开同一个文件会打开多个编辑窗口的问题
This commit is contained in:
parent
5b701f5333
commit
90372168b4
@ -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(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user