From e54bd0a44713f8bc9e5fdf891790d3424fd3f359 Mon Sep 17 00:00:00 2001
From: Azure <983547216@qq.com>
Date: Sat, 11 Oct 2025 12:10:35 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 1 -
pnpm-lock.yaml | 8 ---
src/main.ts | 62 ++++++++------------
src/services/ApplicationSandboxEngine.ts | 12 +---
src/services/SystemServiceIntegration.ts | 75 +++++++++++-------------
tsconfig.app.json | 1 -
6 files changed, 58 insertions(+), 101 deletions(-)
diff --git a/package.json b/package.json
index 9fcb997..acba4d0 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,6 @@
"lit": "^3.3.1",
"lodash": "^4.17.21",
"pinia": "^3.0.3",
- "reflect-metadata": "^0.2.2",
"uuid": "^11.1.0",
"vue": "^3.5.18"
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b737e36..9eaf67d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -20,9 +20,6 @@ importers:
pinia:
specifier: ^3.0.3
version: 3.0.3(typescript@5.8.3)(vue@3.5.18(typescript@5.8.3))
- reflect-metadata:
- specifier: ^0.2.2
- version: 0.2.2
uuid:
specifier: ^11.1.0
version: 11.1.0
@@ -1371,9 +1368,6 @@ packages:
resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==}
engines: {node: '>= 14.18.0'}
- reflect-metadata@0.2.2:
- resolution: {integrity: sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==}
-
rfdc@1.4.1:
resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==}
@@ -2908,8 +2902,6 @@ snapshots:
readdirp@4.1.2: {}
- reflect-metadata@0.2.2: {}
-
rfdc@1.4.1: {}
rollup@4.46.2:
diff --git a/src/main.ts b/src/main.ts
index f47f668..d7953c4 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,16 +1,22 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { naiveUi } from '@/common/naive-ui/components.ts'
+import { SystemServiceIntegration } from '@/services/SystemServiceIntegration'
import { registerBuiltInApps } from '@/apps'
-import { systemBootstrapper } from '@/services/di/SystemBootstrapper'
-import { ServiceProvider } from '@/services/di/ServiceProvider'
-import { ServiceIds } from '@/services/di/ServiceRegistry'
import 'virtual:uno.css'
import './css/basic.css'
import App from './ui/App.vue'
+// 注册内置应用
+registerBuiltInApps()
+
+// 初始化系统服务
+const systemService = new SystemServiceIntegration({
+ debug: import.meta.env.DEV
+})
+
// 创建应用实例
const app = createApp(App)
@@ -18,58 +24,38 @@ const app = createApp(App)
app.use(createPinia())
app.use(naiveUi)
-// 全局错误处理
-app.config.errorHandler = (error, instance, info) => {
- console.error('Vue应用错误:', error, info)
-}
+// 提供系统服务给组件使用
+app.provide('systemService', systemService)
-// 启动应用函数
-async function startApplication() {
- try {
- // 注册内置应用
- registerBuiltInApps()
-
- console.log('正在启动桌面系统...')
-
- // 使用系统启动器初始化依赖注入系统和所有服务
- const success = await systemBootstrapper.bootstrap({
- debug: import.meta.env.DEV,
- autoCleanup: true
- })
-
- if (!success) {
- throw new Error('系统启动失败')
- }
-
- // 获取系统服务并提供给Vue应用
- const systemService = ServiceProvider.getSystemService()
- app.provide('systemService', systemService)
-
- // 挂载应用
+// 初始化系统服务然后挂载应用
+systemService
+ .initialize()
+ .then(() => {
app.mount('#app')
console.log('桌面系统启动完成')
-
- } catch (error) {
+ })
+ .catch((error) => {
console.error('系统启动失败:', error)
// 显示错误信息
document.body.innerHTML = `
系统启动失败
-
错误信息: ${error instanceof Error ? error.message : '未知错误'}
+
错误信息: ${error.message}
`
- }
-}
+ })
-// 启动应用
-startApplication()
+// 全局错误处理
+app.config.errorHandler = (error, instance, info) => {
+ console.error('Vue应用错误:', error, info)
+}
// 在页面卸载时清理系统服务
window.addEventListener('beforeunload', () => {
- systemBootstrapper.shutdown()
+ systemService.shutdown()
})
diff --git a/src/services/ApplicationSandboxEngine.ts b/src/services/ApplicationSandboxEngine.ts
index daed515..37758f3 100644
--- a/src/services/ApplicationSandboxEngine.ts
+++ b/src/services/ApplicationSandboxEngine.ts
@@ -101,24 +101,14 @@ export interface SandboxEvents {
/**
* 应用沙箱引擎类
*/
-import { ServiceProvider, Inject } from './di/ServiceProvider'
-import type { IServiceContainer } from './di/IServiceContainer'
-
export class ApplicationSandboxEngine {
- // 服务容器
- private serviceContainer: IServiceContainer
-
private sandboxes = reactive(new Map())
private performanceData = reactive(new Map())
private monitoringInterval: number | null = null
-
- // 资源服务
- @Inject('resourceService')
private resourceService: ResourceService
- constructor(resourceService: ResourceService, serviceContainer: IServiceContainer) {
+ constructor(resourceService: ResourceService) {
this.resourceService = resourceService
- this.serviceContainer = serviceContainer
this.startPerformanceMonitoring()
}
diff --git a/src/services/SystemServiceIntegration.ts b/src/services/SystemServiceIntegration.ts
index fcf65a1..af0533f 100644
--- a/src/services/SystemServiceIntegration.ts
+++ b/src/services/SystemServiceIntegration.ts
@@ -1,10 +1,11 @@
import { reactive, ref } from 'vue'
+import { EventBuilderImpl } from '@/events/impl/EventBuilderImpl'
import type { IEventBuilder, IEventMap, WindowFormDataUpdateParams } from '@/events/IEventBuilder'
-import { ResourceService, ResourceType } from './ResourceService'
-import { ServiceProvider, Inject } from './di/ServiceProvider'
-import type { IServiceContainer } from './di/IServiceContainer'
-import { ServiceIds } from './di/ServiceRegistry'
-import { WindowFormService } from './WindowFormService'
+import type { ResourceType } from './ResourceService'
+
+// 导入所有服务
+import { WindowFormService } from './WindowFormService.ts'
+import { ResourceService } from './ResourceService'
import { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
import { ApplicationLifecycleManager } from './ApplicationLifecycleManager'
import { externalAppDiscovery } from './ExternalAppDiscovery'
@@ -54,24 +55,12 @@ export class SystemServiceIntegration {
private config: SystemServiceConfig
private startTime: Date
- // 核心服务实例 - 使用依赖注入
- @Inject(ServiceIds.EVENT_BUILDER)
- private eventBus!: IEventBuilder
-
- @Inject(ServiceIds.WINDOW_FORM_SERVICE)
- private windowFormService!: any
-
- @Inject(ServiceIds.RESOURCE_SERVICE)
- private resourceService!: any
-
- @Inject(ServiceIds.SANDBOX_ENGINE)
- private sandboxEngine!: any
-
- @Inject(ServiceIds.LIFECYCLE_MANAGER)
- private lifecycleManager!: any
-
- @Inject(ServiceIds.EXTERNAL_APP_DISCOVERY)
- private externalAppDiscovery!: any
+ // 核心服务实例
+ private eventBus: IEventBuilder
+ private windowFormService!: WindowFormService
+ private resourceService!: ResourceService
+ private sandboxEngine!: ApplicationSandboxEngine
+ private lifecycleManager!: ApplicationLifecycleManager
// 系统状态
private systemStatus = reactive({
@@ -89,9 +78,8 @@ export class SystemServiceIntegration {
// 性能监控
private cleanupInterval: number | null = null
private performanceInterval: number | null = null
- private serviceContainer: IServiceContainer
- constructor(serviceContainer: IServiceContainer, config: SystemServiceConfig = {}) {
+ constructor(config: SystemServiceConfig = {}) {
this.config = {
debug: false,
autoCleanup: true,
@@ -100,7 +88,7 @@ export class SystemServiceIntegration {
}
this.startTime = new Date()
- this.serviceContainer = serviceContainer
+ this.eventBus = new EventBuilderImpl()
this.setupGlobalErrorHandling()
}
@@ -110,31 +98,36 @@ export class SystemServiceIntegration {
*/
public async initialize(): Promise {
if (this.initialized.value) {
- console.warn('系统服务已经初始化')
- return
+ throw new Error('系统服务已初始化')
}
try {
console.log('开始初始化系统服务...')
- // 启动自动清理(如果启用)
+ // 按依赖顺序初始化服务
+ await this.initializeServices()
+
+ // 设置服务间通信
+ this.setupServiceCommunication()
+
+ // 设置SDK消息处理
+ this.setupSDKMessageHandling()
+
+ // 启动自动清理
if (this.config.autoCleanup) {
this.startAutoCleanup()
}
- // 更新系统状态
- this.systemStatus.initialized = true
- this.systemStatus.running = true
+ // 启动外置应用发现服务
+ // 注意:外置应用发现服务统一由 SystemServiceIntegration 管理,
+ // ApplicationLifecycleManager 只负责使用已发现的应用,避免重复启动
+ console.log('启动外置应用发现服务...')
+ await externalAppDiscovery.startDiscovery()
+
this.initialized.value = true
this.running.value = true
-
- // 标记所有服务状态为已启动
- this.systemStatus.servicesStatus = {
- windowFormService: true,
- resourceService: true,
- sandboxEngine: true,
- lifecycleManager: true
- }
+ this.systemStatus.initialized = true
+ this.systemStatus.running = true
console.log('系统服务初始化完成')
} catch (error) {
@@ -144,8 +137,6 @@ export class SystemServiceIntegration {
}
}
- // ... 保留其他现有方法
-
/**
* 获取系统状态
*/
diff --git a/tsconfig.app.json b/tsconfig.app.json
index 9a4cafd..d292bdb 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -13,7 +13,6 @@
"module": "ESNext",
"strict": true, // 严格模式检查
"experimentalDecorators": true, // 装饰器
- "emitDecoratorMetadata": true, // 元数据反射
"useDefineForClassFields": false,
"strictPropertyInitialization": false, // 严格属性初始化检查
"noUnusedLocals": false, // 检查未使用的局部变量