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

Method queryMainPush

src/main/managers/pluginManager.ts:1561–1623  ·  view source on GitHub ↗

* 查询插件的 mainPush 回调,获取动态搜索结果 * 如果插件尚未加载,会先预加载

(
    pluginPath: string,
    _featureCode: string,
    queryData: { code: string; type: string; payload: string }
  )

Source from the content-addressed store, hash-verified

1559 * 如果插件尚未加载,会先预加载
1560 */
1561 public async queryMainPush(
1562 pluginPath: string,
1563 _featureCode: string,
1564 queryData: { code: string; type: string; payload: string }
1565 ): Promise<any[]> {
1566 console.log('[Plugin][MainPush] query start:', { pluginPath, queryData })
1567 // 确保插件已加载
1568 let plugin = this.pluginViews.find((v) => v.path === pluginPath)
1569 if (!plugin) {
1570 console.log('[Plugin][MainPush] plugin not loaded, preload first:', { pluginPath })
1571 await this.preloadPlugin(pluginPath)
1572 // 等待 dom-ready(最多 5 秒)
1573 plugin = this.pluginViews.find((v) => v.path === pluginPath)
1574 if (plugin && !plugin.view.webContents.isDestroyed()) {
1575 console.log('[Plugin][MainPush] waiting dom-ready after preload:', { pluginPath })
1576 await this.assemblyCoordinator.waitForDomReady(plugin.view, 5000)
1577 }
1578 }
1579
1580 if (!plugin || plugin.view.webContents.isDestroyed()) {
1581 console.warn('[Plugin][MainPush] query aborted: plugin unavailable', { pluginPath })
1582 return []
1583 }
1584
1585 const callId = `mp_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`
1586
1587 return new Promise((resolve) => {
1588 const timeout = setTimeout(() => resolve([]), 3000) // 3 秒超时
1589
1590 plugin!.view.webContents.ipc.once(`main-push-result-${callId}`, (_event, result) => {
1591 clearTimeout(timeout)
1592 console.log('[Plugin][MainPush] result received:', {
1593 pluginPath,
1594 callId,
1595 success: !!result?.success,
1596 resultCount: Array.isArray(result?.results) ? result.results.length : 0
1597 })
1598 if (result.success && Array.isArray(result.results)) {
1599 // 处理图标路径:将相对路径转为 file:// URL(保留原始 icon 不变,用 _resolvedIcon 展示)
1600 const processed = result.results.map((item: any) => {
1601 if (
1602 item.icon &&
1603 !item.icon.startsWith('http') &&
1604 !item.icon.startsWith('file:') &&
1605 !item.icon.startsWith('data:')
1606 ) {
1607 return {
1608 ...item,
1609 _resolvedIcon: pathToFileURL(path.join(pluginPath, item.icon)).href
1610 }
1611 }
1612 return item
1613 })
1614 resolve(processed)
1615 } else {
1616 resolve([])
1617 }
1618 })

Callers 2

queryMainPushPluginsFunction · 0.80
setupIPCMethod · 0.80

Calls 2

preloadPluginMethod · 0.95
waitForDomReadyMethod · 0.80

Tested by

no test coverage detected