zdg #362

Merged
zhengdegang merged 2 commits from zdg into main 2024-10-24 17:03:05 +08:00
2 changed files with 11 additions and 7 deletions

View File

@ -271,12 +271,13 @@ app.on('window-all-closed', () => {
function handleAll() {
const chatInstance = chat.initialize() // im-chat 实例
// 新窗口创建-监听
ipcMain.on('new-window', (e, data) => {
ipcMain.handle('new-window', (e, data) => {
const { id, type } = data
const win = BrowserWindow.fromId(id)
win.type = type // 绑定独立标识
remote.enable(win.webContents) // 开启远程服务
chatInstance.enable(win.webContents) // 开启im-chat
console.log(`主进程 [${type}]: 窗口注册-远程代理-完毕(${Date.now()})`)
})
// 用于监听-状态管理变化-同步所有窗口
ipcMain.handle('pinia-state-change', (e, storeName, jsonStr) => {

View File

@ -131,7 +131,7 @@ export const createWindow = async (type, data) => {
data.isConsole = true // 是否开启控制台
data.isWeb = false // 是否开启web安全
data.option = {...defOption, ...option}
wins_tool = await toolWindow(data)
wins_tool = await toolWindow(type, data)
wins_tool.type = type // 唯一标识
wins_tool.show()
wins_tool.setFullScreen(true) // 设置窗口为全屏
@ -161,7 +161,7 @@ export const createWindow = async (type, data) => {
}
data.isConsole = true // 是否开启控制台
data.option = {...defOption, ...option}
const win = await toolWindow(data)
const win = await toolWindow(type, data)
win.type = type // 唯一标识
win.show()
win.setFullScreen(true) // 设置窗口为全屏
@ -193,7 +193,7 @@ export const createWindow = async (type, data) => {
}
data.isConsole = true // 是否开启控制台
data.option = {...defOption, ...option}
winChild = await toolWindow(data)
winChild = await toolWindow(type, data)
winChild.type = type // 唯一标识
winChild.show()
winChild.setFullScreen(false) // 设置窗口为全屏
@ -213,7 +213,7 @@ export const createWindow = async (type, data) => {
* @author: zdg
* @date 2021-07-05 14:07:01
*/
export function toolWindow({url, isConsole, isWeb=true, option={}}) {
export function toolWindow(type, {url, isConsole, isWeb=true, option={}}) {
// width = window.screen.width
let width = option?.width || 800
let height = option?.height || 600
@ -221,7 +221,7 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) {
const devUrl = `${BaseUrl}${url}`
const buildUrl = path.join(__dirname, 'index.html')
const urlAll = isDev ? devUrl : buildUrl
return new Promise((resolve) => {
return new Promise(async(resolve) => {
const config = {
width, height,
icon: path.join(appPath, '/resources/logo2.ico'),
@ -236,6 +236,9 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) {
}
// 创建-新窗口
let win = new Remote.BrowserWindow(config)
// 新窗口-创建事件(如:主进程加载远程服务)
await ipcMsgInvoke('new-window', {id:win.id, type})
console.log(`渲染进程 [${type}]: 窗口创建-成功${Date.now()}`)
if (!isDev) win.loadFile(urlAll,{hash: url}) // 加载文件
else win.loadURL(urlAll) // 加载url
win.once('ready-to-show', () => { // 窗口加载完成
@ -281,7 +284,7 @@ const eventHandles = (type, win) => {
})
// 新窗口-创建事件(如:主进程加载远程服务)
ipcRenderer.send('new-window', {id:win.id, type})
// ipcRenderer.send('new-window', {id:win.id, type})
}
switch(type) {
case 'tool-sphere': { // 创建-悬浮球