之前的
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -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:
|
||||
|
||||
62
src/main.ts
62
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 = `
|
||||
<div style="display: flex; justify-content: center; align-items: center; height: 100vh; font-family: sans-serif;">
|
||||
<div style="text-align: center; color: #e74c3c;">
|
||||
<h1>系统启动失败</h1>
|
||||
<p>错误信息: ${error instanceof Error ? error.message : '未知错误'}</p>
|
||||
<p>错误信息: ${error.message}</p>
|
||||
<button onclick="location.reload()" style="padding: 10px 20px; margin-top: 20px; cursor: pointer;">
|
||||
重新加载
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 启动应用
|
||||
startApplication()
|
||||
// 全局错误处理
|
||||
app.config.errorHandler = (error, instance, info) => {
|
||||
console.error('Vue应用错误:', error, info)
|
||||
}
|
||||
|
||||
// 在页面卸载时清理系统服务
|
||||
window.addEventListener('beforeunload', () => {
|
||||
systemBootstrapper.shutdown()
|
||||
systemService.shutdown()
|
||||
})
|
||||
|
||||
@@ -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<string, SandboxInstance>())
|
||||
private performanceData = reactive(new Map<string, SandboxPerformance[]>())
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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<any>
|
||||
|
||||
@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<any>
|
||||
private windowFormService!: WindowFormService
|
||||
private resourceService!: ResourceService
|
||||
private sandboxEngine!: ApplicationSandboxEngine
|
||||
private lifecycleManager!: ApplicationLifecycleManager
|
||||
|
||||
// 系统状态
|
||||
private systemStatus = reactive<SystemStatus>({
|
||||
@@ -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<any>()
|
||||
|
||||
this.setupGlobalErrorHandling()
|
||||
}
|
||||
@@ -110,31 +98,36 @@ export class SystemServiceIntegration {
|
||||
*/
|
||||
public async initialize(): Promise<void> {
|
||||
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 {
|
||||
}
|
||||
}
|
||||
|
||||
// ... 保留其他现有方法
|
||||
|
||||
/**
|
||||
* 获取系统状态
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
"module": "ESNext",
|
||||
"strict": true, // 严格模式检查
|
||||
"experimentalDecorators": true, // 装饰器
|
||||
"emitDecoratorMetadata": true, // 元数据反射
|
||||
"useDefineForClassFields": false,
|
||||
"strictPropertyInitialization": false, // 严格属性初始化检查
|
||||
"noUnusedLocals": false, // 检查未使用的局部变量
|
||||
|
||||
Reference in New Issue
Block a user