11import { is } from '@electron-toolkit/utils'
2- import { app , shell , BrowserWindow , ipcMain , dialog , protocol as eProtocol , net } from 'electron'
2+ import {
3+ app ,
4+ shell ,
5+ BrowserWindow ,
6+ ipcMain ,
7+ dialog ,
8+ protocol as eProtocol ,
9+ net ,
10+ MessageChannelMain ,
11+ MessagePortMain
12+ } from 'electron'
313import path , { join } from 'path'
414import icon from '../../resources/icon.png?asset'
515
16+ ipcMain . on ( 'ipc-get-port' , ( event ) => {
17+ const win = BrowserWindow . fromWebContents ( event . sender )
18+ if ( win ) {
19+ const port = logQ . portMap . get ( win )
20+ if ( port ) {
21+ port . close ( )
22+ }
23+ const { port1, port2 } = new MessageChannelMain ( )
24+ logQ . portMap . set ( win , port1 )
25+ event . sender . postMessage ( 'port' , null , [ port2 ] )
26+ // port2.start()
27+ }
28+ } )
629class LogQueue {
730 private static instance : LogQueue | null = null
831 list : any [ ] = [ ]
932 timer : any
1033 mainWin : BrowserWindow | undefined
34+ portMap : Map < BrowserWindow , MessagePortMain > = new Map ( )
1135
1236 private constructor (
1337 public win : BrowserWindow [ ] = [ ] ,
@@ -32,7 +56,9 @@ class LogQueue {
3256 protected startTimer ( ) {
3357 this . timer = setInterval ( ( ) => {
3458 if ( this . list . length ) {
35- this . mainWin ! . webContents . send ( 'ipc-log' , this . list )
59+ this . portMap . forEach ( ( port , win ) => {
60+ port . postMessage ( this . list )
61+ } )
3662 this . list = [ ]
3763 }
3864 } , this . period )
@@ -117,6 +143,7 @@ ipcMain.on('ipc-close-others-windows', (event, arg) => {
117143export function closeAllWindows ( ) {
118144 winMap . forEach ( ( win , key ) => {
119145 //store pos
146+
120147 const pos = win . getBounds ( )
121148 winPosMap . set ( key , {
122149 x : pos ?. x ,
@@ -125,6 +152,10 @@ export function closeAllWindows() {
125152 height : pos ?. height
126153 } )
127154 win . close ( )
155+ const port = logQ . portMap . get ( win )
156+ if ( port ) {
157+ port . close ( )
158+ }
128159 } )
129160}
130161
@@ -140,6 +171,10 @@ export function closeWindow(id: string) {
140171 height : pos ?. height
141172 } )
142173 win . close ( )
174+ const port = logQ . portMap . get ( win )
175+ if ( port ) {
176+ port . close ( )
177+ }
143178 }
144179}
145180export function minimizeWindow ( id : string ) {
0 commit comments