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

Method setupIPC

src/main/core/superPanelManager.ts:568–831  ·  view source on GitHub ↗

* 设置 IPC 监听

()

Source from the content-addressed store, hash-verified

566 * 设置 IPC 监听
567 */
568 private setupIPC(): void {
569 // 主窗口返回搜索结果(携带剪贴板内容)
570 ipcMain.on(
571 'super-panel-search-result',
572 (_event, data: { results: any[]; clipboardContent?: ClipboardContent }) => {
573 this.sendToSuperPanel('super-panel-data', {
574 type: 'search',
575 results: data.results,
576 clipboardContent: data.clipboardContent,
577 windowInfo: this.currentWindowInfo
578 })
579 }
580 )
581
582 // 超级面板启动指令 → 转发给主渲染进程处理
583 ipcMain.handle('super-panel:launch', async (_event, command: any) => {
584 try {
585 // 隐藏超级面板
586 this.hideWindow()
587
588 // direct 类型(系统应用/系统设置)直接在主进程启动,不唤出主窗口
589 if (command.type === 'direct') {
590 await launchApp(command.path)
591 return { success: true }
592 }
593
594 if (!this.mainWindow || this.mainWindow.isDestroyed()) {
595 return { success: false, error: '主窗口不可用' }
596 }
597
598 // 先显示主窗口,确保渲染进程能正常处理启动指令
599 if (this.currentWindowInfo) {
600 windowManager.setPreviousActiveWindow(this.currentWindowInfo)
601 }
602 this.mainWindow.show()
603
604 // 转发给主渲染进程,由 handleSelectApp 统一处理
605 // 携带剪贴板内容作为 payload 来源
606 this.mainWindow.webContents.send('super-panel-launch', {
607 command,
608 clipboardContent: this.currentClipboardContent,
609 windowInfo: command.windowInfo || this.currentWindowInfo
610 })
611
612 return { success: true }
613 } catch (error) {
614 console.error('[SuperPanel] 超级面板启动指令失败:', error)
615 return {
616 success: false,
617 error: error instanceof Error ? error.message : '未知错误'
618 }
619 }
620 })
621
622 // 超级面板窗口准备好接收数据
623 ipcMain.on('super-panel:ready', () => {
624 this.windowReady = true
625 // 发送所有缓存的消息

Callers 1

initMethod · 0.95

Calls 11

sendToSuperPanelMethod · 0.95
hideWindowMethod · 0.95
loadPinnedCommandsMethod · 0.95
onMethod · 0.80
showMethod · 0.80
launchAppFunction · 0.50
showWindowMethod · 0.45
dbPutMethod · 0.45
dbGetMethod · 0.45

Tested by

no test coverage detected