* 重启组件
(id: string)
| 252 | * 重启组件 |
| 253 | */ |
| 254 | public async restartComponent(id: string): Promise<boolean> { |
| 255 | const component = this.components.get(id); |
| 256 | if (!component) { |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | try { |
| 261 | this.log(`重启组件: ${id}`); |
| 262 | |
| 263 | // 销毁组件 |
| 264 | await component.destroy(); |
| 265 | this.emit('componentDestroyed', { id, component }); |
| 266 | |
| 267 | // 重新初始化组件 |
| 268 | await component.init(); |
| 269 | this.emit('componentInitialized', { id, component }); |
| 270 | |
| 271 | this.log(`组件 "${id}" 重启完成`); |
| 272 | this.emit('componentRestarted', { id, component }); |
| 273 | return true; |
| 274 | } catch (error) { |
| 275 | this.log(`组件 "${id}" 重启失败: ${error}`); |
| 276 | this.emit('componentRestartFailed', { id, component, error: error as Error }); |
| 277 | throw error; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * 获取组件状态 |