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

Method createNewPluginView

src/main/managers/pluginManager.ts:598–708  ·  view source on GitHub ↗

* 创建全新的插件视图(缓存未命中时调用)

(
    pluginPath: string,
    pluginInfoFromDB: any,
    featureCode: string,
    cmdName?: string,
    assembly?: AssemblySession
  )

Source from the content-addressed store, hash-verified

596 * 创建全新的插件视图(缓存未命中时调用)
597 */
598 private async createNewPluginView(
599 pluginPath: string,
600 pluginInfoFromDB: any,
601 featureCode: string,
602 cmdName?: string,
603 assembly?: AssemblySession
604 ): Promise<void> {
605 if (!this.mainWindow) return
606
607 try {
608 this.assemblyCoordinator.trace('create-new-view-start', {
609 assemblyId: assembly?.id,
610 pluginPath,
611 featureCode
612 })
613 // 插件加载时,先将窗口高度设置为 1px,避免节流
614 api.resizeWindow(WINDOW_INITIAL_HEIGHT + 1)
615 const pluginConfig = this.readPluginConfig(pluginPath)
616 const isDevelopment = !!pluginInfoFromDB?.isDevelopment
617 const effectiveName = pluginInfoFromDB?.name || pluginConfig.name
618 const { pluginUrl } = this.resolvePluginUrl(pluginPath, pluginConfig, isDevelopment)
619
620 const preloadPath = pluginConfig.preload
621 ? path.join(pluginPath, pluginConfig.preload)
622 : undefined
623
624 const sess = await this.setupPluginSession(effectiveName, pluginPath)
625 this.pluginView = this.createPluginWebContentsView(sess, preloadPath)
626
627 // 注册主窗口专属的事件监听
628 this.registerMainWindowPluginEvents(this.pluginView, pluginPath)
629
630 this.mainWindow.contentView.addChildView(this.pluginView)
631
632 // 设置初始布局(使用固定宽度常量,避免多显示器 DPI 缩放导致尺寸漂移)
633 const windowWidth = WINDOW_WIDTH
634 // 设置初始高度为 1px,避免节流
635 this.pluginView.setBounds({ x: 0, y: WINDOW_INITIAL_HEIGHT, width: windowWidth, height: 1 })
636
637 // 缓存新创建的视图
638 const logoUrl = this.buildPluginLogoUrl(pluginPath, pluginConfig.logo)
639 const pluginInfo: PluginViewInfo = {
640 path: pluginPath,
641 name: effectiveName,
642 view: this.pluginView,
643 subInputPlaceholder: '搜索',
644 subInputVisible: false,
645 logo: logoUrl,
646 isDevelopment,
647 backgroundRunning: !!pluginConfig.pluginSetting?.backgroundRunning,
648 single: pluginConfig.pluginSetting?.single
649 }
650 this.pluginViews.push(pluginInfo)
651 this.currentPluginPath = pluginPath
652
653 // 通知渲染进程插件已打开
654 this.sendPluginOpenedEvent(
655 pluginConfig,

Callers 1

createPluginViewMethod · 0.95

Calls 15

readPluginConfigMethod · 0.95
resolvePluginUrlMethod · 0.95
setupPluginSessionMethod · 0.95
buildPluginLogoUrlMethod · 0.95
sendPluginOpenedEventMethod · 0.95
processPluginModeMethod · 0.95
sendPluginLoadedEventMethod · 0.95
forceRepaintViewMethod · 0.95
traceMethod · 0.80
markDomReadyMethod · 0.80

Tested by

no test coverage detected