MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / setupIPC

Method setupIPC

src/main/api/plugin/window.ts:180–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

178 }
179
180 private setupIPC(): void {
181 // 发送消息到父窗口
182 ipcMain.on('send-to-parent', (event, channel: string, ...args: any[]) => {
183 pluginWindowManager.sendToParent(event.sender, channel, args)
184 })
185
186 // 显示主窗口
187 ipcMain.handle('show-main-window', () => {
188 windowManager.showWindow()
189 })
190
191 // 隐藏主窗口
192 ipcMain.handle('hide-main-window', (_event, isRestorePreWindow: boolean = true) => {
193 windowManager.hideWindow(isRestorePreWindow)
194 })
195
196 // ipcRenderer.sendTo polyfill
197 ipcMain.on('ipc-send-to', (event, webContentsId: number, channel: string, ...args: any[]) => {
198 const senderId = event.sender.id
199 try {
200 const targetWebContents = webContents.fromId(webContentsId)
201 if (targetWebContents && !targetWebContents.isDestroyed()) {
202 targetWebContents.send('__ipc_sendto_relay__', { senderId, channel, args })
203 } else {
204 console.warn(`[pluginWindow:method] 目标 webContents 不存在或已销毁: ${webContentsId}`)
205 }
206 } catch (error) {
207 console.error('[pluginWindow:method] 转发消息失败:', error)
208 }
209 })
210
211 // 获取窗口类型(同步方法,供插件使用)
212 ipcMain.on('get-window-type', (event) => {
213 try {
214 const windowType = this.getWindowType(event.sender)
215 event.returnValue = windowType
216 } catch (error) {
217 console.error('[pluginWindow:method] get-window-type error:', error)
218 event.returnValue = 'main'
219 }
220 })
221 }
222
223 /**
224 * 获取窗口类型

Callers 1

initMethod · 0.95

Calls 5

getWindowTypeMethod · 0.95
onMethod · 0.80
sendToParentMethod · 0.80
showWindowMethod · 0.45
hideWindowMethod · 0.45

Tested by

no test coverage detected