()
| 800 | |
| 801 | // 隐藏插件视图 |
| 802 | public hidePluginView(): void { |
| 803 | if (this.pluginView && this.mainWindow) { |
| 804 | const currentPath = this.currentPluginPath |
| 805 | const pluginView = this.pluginView |
| 806 | console.log('[Plugin] 隐藏插件视图:', { |
| 807 | currentPath, |
| 808 | hasAssembly: this.assemblyCoordinator.hasCurrentSession() |
| 809 | }) |
| 810 | |
| 811 | // 发送插件退出事件(isKill=false 表示正常退出) |
| 812 | if (!pluginView.webContents.isDestroyed()) { |
| 813 | void this.assemblyCoordinator.dispatchLifecycleEvent(pluginView, 'PluginOut', false) |
| 814 | } |
| 815 | |
| 816 | // 获取插件名称 |
| 817 | const cached = this.pluginViews.find((v) => v.path === currentPath) |
| 818 | const pluginName = cached?.name |
| 819 | |
| 820 | // 仅移除视图以达到隐藏效果,但保留实例以便复用 |
| 821 | this.mainWindow.contentView.removeChildView(pluginView) |
| 822 | // 隐藏时按策略决定是否启用节流 |
| 823 | this.applyBackgroundThrottlingByPolicy(pluginView, currentPath, true) |
| 824 | console.log('[Plugin] Plugin WebContentsView 已隐藏,缓存保留') |
| 825 | |
| 826 | // 将当前引用清空,但缓存仍保留 |
| 827 | this.pluginView = null |
| 828 | this.currentPluginPath = null |
| 829 | this.assemblyCoordinator.abortCurrentSession('hide-view-abort-assembly') |
| 830 | this.assemblyCoordinator.clearCurrentSession() |
| 831 | |
| 832 | // 通知渲染进程插件已关闭 |
| 833 | this.mainWindow.webContents.send('plugin-closed') |
| 834 | |
| 835 | // 检查是否需要终止插件 |
| 836 | if (pluginName && currentPath) { |
| 837 | if (pluginWindowManager.hasWindowsByPlugin(currentPath)) { |
| 838 | console.log(`[Plugin] 插件 ${pluginName} 还有打开的子窗口,暂不终止进程`) |
| 839 | } else { |
| 840 | this.checkAndKillPlugin(pluginName, currentPath) |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | // 检查并终止插件 |
| 847 | private checkAndKillPlugin(pluginName: string, pluginPath: string): void { |
no test coverage detected