* Initialize engine once at module level * 在模块级别初始化引擎一次
(canvasId: string)
| 61 | * 在模块级别初始化引擎一次 |
| 62 | */ |
| 63 | async function initializeEngine(canvasId: string): Promise<void> { |
| 64 | if (engineInitialized || engineInitializing) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | engineInitializing = true; |
| 69 | |
| 70 | try { |
| 71 | const engine = EngineService.getInstance(); |
| 72 | await engine.initialize(canvasId); |
| 73 | |
| 74 | // Initialize sync service |
| 75 | // 初始化同步服务 |
| 76 | try { |
| 77 | const messageHub = Core.services.resolve(MessageHub); |
| 78 | const entityStore = Core.services.resolve(EntityStoreService); |
| 79 | if (messageHub && entityStore) { |
| 80 | EditorEngineSync.getInstance().initialize(messageHub, entityStore); |
| 81 | } |
| 82 | } catch (syncError) { |
| 83 | console.warn('Failed to initialize sync service | 同步服务初始化失败:', syncError); |
| 84 | } |
| 85 | |
| 86 | engineInitialized = true; |
| 87 | } finally { |
| 88 | engineInitializing = false; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Hook for managing engine lifecycle in React components. |
no test coverage detected