diff --git a/package.json b/package.json index 99b4789..3abf345 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "electron-app", - "version": "1.0.1", + "name": "aix-win", + "version": "1.0.2", "description": "An Electron application with Vue", "main": "./out/main/index.js", "author": "example.com", diff --git a/src/main/index.js b/src/main/index.js index 673da1f..653c83c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -103,11 +103,12 @@ function createMainWindow() { remote.enable(mainWindow.webContents) } -// 作业窗口相关-开发中 -let linkWindow +// 打开外部链接窗口 +let linkWin = {} async function createLinkWin(data) { - if (linkWindow) return - linkWindow = new BrowserWindow({ + if (linkWin[data.key]) return + + linkWin[data.key] = new BrowserWindow({ show: false, frame: true, maximizable: true, @@ -120,9 +121,10 @@ async function createLinkWin(data) { contextIsolation: true } }) - linkWindow.type = 'link' // 唯一标识 + linkWin[data.key].type = 'link' // 唯一标识 + let cookieDetails = { ...data.cookieData } - await linkWindow.webContents.session.cookies + await linkWin[data.key].webContents.session.cookies .set(cookieDetails) .then(() => { console.log('Cookie is successful') @@ -131,14 +133,15 @@ async function createLinkWin(data) { console.error('Cookie is error', error) }) data.fullPath = data.fullPath.replaceAll('//', '/') - linkWindow.loadURL(data.fullPath) + linkWin[data.key].loadURL(data.fullPath) - linkWindow.once('ready-to-show', () => { - linkWindow.show() - linkWindow.maximize() + linkWin[data.key].once('ready-to-show', () => { + linkWin[data.key].show() + linkWin[data.key].maximize() }) - linkWindow.on('closed', () => { - linkWindow = null + linkWin[data.key].on('closed', () => { + linkWin[data.key] = null + delete linkWin[data.key] }) } @@ -202,14 +205,8 @@ app.on('ready', () => { ipcMain.on('openWindow', (e, data) => { createLinkWin(data) }) - // 新窗口创建-监听 - ipcMain.on('new-window', (e, data) => { - const { id, type } = data - const win = BrowserWindow.fromId(id) - win.type = type // 绑定独立标识 - remote.enable(win.webContents) // 开启远程服务 - }) - + // zdg: 消息监听 + handleAll() // 打开-登录窗口 createLoginWindow() @@ -226,3 +223,24 @@ app.on('window-all-closed', () => { app.quit() } }) + +// 监听全局事件 +function handleAll() { + // 新窗口创建-监听 + ipcMain.on('new-window', (e, data) => { + const { id, type } = data + const win = BrowserWindow.fromId(id) + win.type = type // 绑定独立标识 + remote.enable(win.webContents) // 开启远程服务 + }) + // 用于监听-状态管理变化-同步所有窗口 + ipcMain.handle('pinia-state-change', (e, storeName, jsonStr) => { + for(const curWin of BrowserWindow.getAllWindows()){ + const id = curWin.webContents.id + const bool = id !== e.sender.id && !curWin.isDestroyed() + if (bool) { // 除了消息发送窗口和销毁的窗口 其他都发送 + curWin.webContents.send('pinia-state-set', storeName, jsonStr) + } + } + }) +} \ No newline at end of file diff --git a/src/renderer/index.html b/src/renderer/index.html index 68cd483..3441296 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -2,7 +2,7 @@ - Electron + AIx智慧教育 -