(
placeholder?: string,
isFocus?: boolean,
event?: Electron.IpcMainInvokeEvent | Electron.IpcMainEvent
)
| 104 | } |
| 105 | |
| 106 | private setSubInput( |
| 107 | placeholder?: string, |
| 108 | isFocus?: boolean, |
| 109 | event?: Electron.IpcMainInvokeEvent | Electron.IpcMainEvent |
| 110 | ): boolean { |
| 111 | try { |
| 112 | // 判断插件是在主窗口还是分离窗口 |
| 113 | const targetWindow = event |
| 114 | ? detachedWindowManager.getWindowByPluginWebContents(event.sender.id) || this.mainWindow |
| 115 | : this.mainWindow |
| 116 | |
| 117 | if (!targetWindow) { |
| 118 | console.warn('[PluginUI] 无法找到目标窗口') |
| 119 | return false |
| 120 | } |
| 121 | |
| 122 | // 调用 setSubInput 时,显示输入框 |
| 123 | targetWindow.webContents.send('update-sub-input-visible', true) |
| 124 | |
| 125 | targetWindow.webContents.send('update-sub-input-placeholder', { |
| 126 | placeholder: placeholder || '搜索' |
| 127 | }) |
| 128 | |
| 129 | // 如果插件在主窗口,更新 pluginManager 的状态 |
| 130 | if (targetWindow === this.mainWindow) { |
| 131 | this.pluginManager?.setSubInputPlaceholder(placeholder || '搜索') |
| 132 | // 更新可见性状态 |
| 133 | if (event) { |
| 134 | const pluginInfo = this.pluginManager?.getPluginInfoByWebContents(event.sender) |
| 135 | if (pluginInfo) { |
| 136 | this.pluginManager?.setSubInputVisible(pluginInfo.path, true) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | console.log('[PluginUI] 设置子输入框 placeholder:', { placeholder, isFocus }) |
| 142 | |
| 143 | // 如果 isFocus 为 true,聚焦子输入框 |
| 144 | if (isFocus) { |
| 145 | this.subInputFocus(event) |
| 146 | } |
| 147 | |
| 148 | return true |
| 149 | } catch (error: unknown) { |
| 150 | console.error('[PluginUI] 设置子输入框失败:', error) |
| 151 | return false |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | private removeSubInput(event?: Electron.IpcMainInvokeEvent | Electron.IpcMainEvent): boolean { |
| 156 | try { |
no test coverage detected