* 确保目标插件和目标工具已就绪。 * 插件未运行时会先后台预加载,然后等待 preload 完成 registerTool。
(
pluginPath: string,
toolName: string
)
| 165 | * 插件未运行时会先后台预加载,然后等待 preload 完成 registerTool。 |
| 166 | */ |
| 167 | public async ensurePluginToolReady( |
| 168 | pluginPath: string, |
| 169 | toolName: string |
| 170 | ): Promise<WebContents | null> { |
| 171 | let webContents = this.pluginManager?.getPluginWebContentsByPath(pluginPath) ?? null |
| 172 | if (!webContents) { |
| 173 | await this.pluginManager?.preloadPlugin(pluginPath) |
| 174 | webContents = this.pluginManager?.getPluginWebContentsByPath(pluginPath) ?? null |
| 175 | } |
| 176 | if (!webContents) return null |
| 177 | |
| 178 | if (this.isToolRegistered(webContents, toolName)) { |
| 179 | return webContents |
| 180 | } |
| 181 | |
| 182 | // 预加载后的 preload 注册是异步的,这里等待插件完成 registerTool。 |
| 183 | await this.waitForToolRegistration(webContents, toolName) |
| 184 | return this.isToolRegistered(webContents, toolName) ? webContents : null |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * 检查某个工具是否已在指定 WebContents 中注册。 |
no test coverage detected