(projectPath: string)
| 706 | }, [initialized, t, showToast]); |
| 707 | |
| 708 | const handleOpenRecentProject = async (projectPath: string) => { |
| 709 | try { |
| 710 | setIsLoading(true, t('loading.step1')); |
| 711 | |
| 712 | const projectService = Core.services.resolve(ProjectService); |
| 713 | |
| 714 | if (!projectService) { |
| 715 | console.error('Required services not available'); |
| 716 | setIsLoading(false); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | projectServiceRef.current = projectService; |
| 721 | await projectService.openProject(projectPath); |
| 722 | |
| 723 | // 注意:插件配置会在引擎初始化后加载和激活 |
| 724 | // Note: Plugin config will be loaded and activated after engine initialization |
| 725 | |
| 726 | // 设置 Tauri project:// 协议的基础路径(用于加载插件等项目文件) |
| 727 | await TauriAPI.setProjectBasePath(projectPath); |
| 728 | |
| 729 | // 更新项目 tsconfig,直接引用引擎类型定义 |
| 730 | // Update project tsconfig to reference engine type definitions directly |
| 731 | try { |
| 732 | await TauriAPI.updateProjectTsconfig(projectPath); |
| 733 | } catch (e) { |
| 734 | console.warn('[App] Failed to update project tsconfig:', e); |
| 735 | } |
| 736 | |
| 737 | const settings = SettingsService.getInstance(); |
| 738 | settings.addRecentProject(projectPath); |
| 739 | |
| 740 | setCurrentProjectPath(projectPath); |
| 741 | |
| 742 | // Scan for available scenes in project |
| 743 | // 扫描项目中可用的场景 |
| 744 | try { |
| 745 | const sceneFiles = await TauriAPI.scanDirectory(`${projectPath}/scenes`, '*.ecs'); |
| 746 | const sceneNames = sceneFiles.map(f => `scenes/${f.split(/[\\/]/).pop()}`); |
| 747 | setAvailableScenes(sceneNames); |
| 748 | } catch (e) { |
| 749 | console.warn('[App] Failed to scan scenes:', e); |
| 750 | } |
| 751 | |
| 752 | // 设置 projectLoaded 为 true,触发主界面渲染(包括 Viewport) |
| 753 | setProjectLoaded(true); |
| 754 | |
| 755 | // 等待引擎初始化完成(Viewport 渲染后会触发引擎初始化) |
| 756 | setIsLoading(true, t('loading.step2')); |
| 757 | const engineService = EngineService.getInstance(); |
| 758 | |
| 759 | // 等待引擎初始化(最多等待 30 秒,因为需要等待 Viewport 渲染) |
| 760 | const engineReady = await engineService.waitForInitialization(30000); |
| 761 | if (!engineReady) { |
| 762 | throw new Error(t('loading.engineTimeoutError')); |
| 763 | } |
| 764 | |
| 765 | // 加载项目插件配置并激活插件(在引擎初始化后、模块系统初始化前) |
no test coverage detected