之前的
This commit is contained in:
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 {
|
||||
}
|
||||
}
|
||||
|
||||
// ... 保留其他现有方法
|
||||
|
||||
/**
|
||||
* 获取系统状态
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user