MCPcopy
hub / github.com/ZToolsCenter/ZTools / setupIPC

Method setupIPC

src/main/core/floatingBallManager.ts:60–137  ·  view source on GitHub ↗

* 设置 IPC 处理器

()

Source from the content-addressed store, hash-verified

58 * 设置 IPC 处理器
59 */
60 private setupIPC(): void {
61 // 悬浮球被点击 → 切换主窗口
62 ipcMain.on('floating-ball-click', () => {
63 this.handleBallClick()
64 })
65
66 // 悬浮球被双击 → 打开目标指令
67 ipcMain.on('floating-ball-double-click', () => {
68 this.handleBallDoubleClick()
69 })
70
71 // 拖拽开始 → 记录鼠标相对窗口的偏移
72 ipcMain.on(
73 'floating-ball-drag-start',
74 (_event, data: { mouseScreenX: number; mouseScreenY: number }) => {
75 if (!this.ballWindow || this.ballWindow.isDestroyed()) return
76 const [winX, winY] = this.ballWindow.getPosition()
77 this.dragOffsetX = data.mouseScreenX - winX
78 this.dragOffsetY = data.mouseScreenY - winY
79 }
80 )
81
82 // 拖拽中 → 移动窗口
83 ipcMain.on('floating-ball-dragging', (_event, data: { screenX: number; screenY: number }) => {
84 if (!this.ballWindow || this.ballWindow.isDestroyed()) return
85 const newX = data.screenX - this.dragOffsetX
86 const newY = data.screenY - this.dragOffsetY
87 this.ballWindow.setPosition(newX, newY, false)
88 })
89
90 // 拖拽结束 → 保存位置
91 ipcMain.on('floating-ball-drag-end', () => {
92 this.savePosition()
93 })
94
95 // 右键菜单
96 ipcMain.on('floating-ball-contextmenu', () => {
97 this.showContextMenu()
98 })
99
100 // 文件拖放到悬浮球
101 ipcMain.on(
102 'floating-ball-file-drop',
103 (_event, files: Array<{ path: string; name: string; isDirectory: boolean }>) => {
104 this.handleFileDrop(files)
105 }
106 )
107
108 // 外部控制:显示/隐藏悬浮球
109 ipcMain.handle('floating-ball:set-enabled', (_event, enabled: boolean) => {
110 return this.setEnabled(enabled)
111 })
112
113 // 外部控制:获取悬浮球状态
114 ipcMain.handle('floating-ball:get-enabled', () => {
115 return this.enabled
116 })
117

Callers 1

initMethod · 0.95

Calls 9

handleBallClickMethod · 0.95
handleBallDoubleClickMethod · 0.95
savePositionMethod · 0.95
showContextMenuMethod · 0.95
handleFileDropMethod · 0.95
setEnabledMethod · 0.95
setLetterMethod · 0.95
setDoubleClickCommandMethod · 0.95
onMethod · 0.80

Tested by

no test coverage detected