* 初始化所有组件
()
| 41 | * 初始化所有组件 |
| 42 | */ |
| 43 | public async init(): Promise<void> { |
| 44 | if (this.isInitialized) { |
| 45 | this.log('组件管理器已经初始化'); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | if (this.isDestroyed) { |
| 50 | throw new Error('组件管理器已被销毁,无法重新初始化'); |
| 51 | } |
| 52 | |
| 53 | this.log('初始化组件管理器...'); |
| 54 | |
| 55 | try { |
| 56 | // 初始化所有组件 |
| 57 | for (const [name, component] of this.components) { |
| 58 | this.log(`初始化组件: ${name}`); |
| 59 | try { |
| 60 | await component.init(); |
| 61 | this.emit('componentInitialized', { id: name, component }); |
| 62 | } catch (error) { |
| 63 | this.log(`组件 ${name} 初始化失败: ${error}`); |
| 64 | this.emit('componentInitializationFailed', { |
| 65 | id: name, |
| 66 | component, |
| 67 | error: error as Error, |
| 68 | }); |
| 69 | throw error; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | this.isInitialized = true; |
| 74 | this.log('组件管理器初始化完成'); |
| 75 | this.emit('initialized'); |
| 76 | } catch (error) { |
| 77 | this.log(`组件管理器初始化失败: ${error}`); |
| 78 | throw error; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * 销毁所有组件 |
no test coverage detected