之前的
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
"lit": "^3.3.1",
|
"lit": "^3.3.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"pinia": "^3.0.3",
|
"pinia": "^3.0.3",
|
||||||
"reflect-metadata": "^0.2.2",
|
|
||||||
"uuid": "^11.1.0",
|
"uuid": "^11.1.0",
|
||||||
"vue": "^3.5.18"
|
"vue": "^3.5.18"
|
||||||
},
|
},
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -20,9 +20,6 @@ importers:
|
|||||||
pinia:
|
pinia:
|
||||||
specifier: ^3.0.3
|
specifier: ^3.0.3
|
||||||
version: 3.0.3(typescript@5.8.3)(vue@3.5.18(typescript@5.8.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:
|
uuid:
|
||||||
specifier: ^11.1.0
|
specifier: ^11.1.0
|
||||||
version: 11.1.0
|
version: 11.1.0
|
||||||
@@ -1371,9 +1368,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==}
|
resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==}
|
||||||
engines: {node: '>= 14.18.0'}
|
engines: {node: '>= 14.18.0'}
|
||||||
|
|
||||||
reflect-metadata@0.2.2:
|
|
||||||
resolution: {integrity: sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==}
|
|
||||||
|
|
||||||
rfdc@1.4.1:
|
rfdc@1.4.1:
|
||||||
resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==}
|
resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==}
|
||||||
|
|
||||||
@@ -2908,8 +2902,6 @@ snapshots:
|
|||||||
|
|
||||||
readdirp@4.1.2: {}
|
readdirp@4.1.2: {}
|
||||||
|
|
||||||
reflect-metadata@0.2.2: {}
|
|
||||||
|
|
||||||
rfdc@1.4.1: {}
|
rfdc@1.4.1: {}
|
||||||
|
|
||||||
rollup@4.46.2:
|
rollup@4.46.2:
|
||||||
|
|||||||
62
src/main.ts
62
src/main.ts
@@ -1,16 +1,22 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import { naiveUi } from '@/common/naive-ui/components.ts'
|
import { naiveUi } from '@/common/naive-ui/components.ts'
|
||||||
|
import { SystemServiceIntegration } from '@/services/SystemServiceIntegration'
|
||||||
import { registerBuiltInApps } from '@/apps'
|
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 'virtual:uno.css'
|
||||||
import './css/basic.css'
|
import './css/basic.css'
|
||||||
|
|
||||||
import App from './ui/App.vue'
|
import App from './ui/App.vue'
|
||||||
|
|
||||||
|
// 注册内置应用
|
||||||
|
registerBuiltInApps()
|
||||||
|
|
||||||
|
// 初始化系统服务
|
||||||
|
const systemService = new SystemServiceIntegration({
|
||||||
|
debug: import.meta.env.DEV
|
||||||
|
})
|
||||||
|
|
||||||
// 创建应用实例
|
// 创建应用实例
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
@@ -18,58 +24,38 @@ const app = createApp(App)
|
|||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(naiveUi)
|
app.use(naiveUi)
|
||||||
|
|
||||||
// 全局错误处理
|
// 提供系统服务给组件使用
|
||||||
app.config.errorHandler = (error, instance, info) => {
|
app.provide('systemService', systemService)
|
||||||
console.error('Vue应用错误:', error, info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 启动应用函数
|
// 初始化系统服务然后挂载应用
|
||||||
async function startApplication() {
|
systemService
|
||||||
try {
|
.initialize()
|
||||||
// 注册内置应用
|
.then(() => {
|
||||||
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)
|
|
||||||
|
|
||||||
// 挂载应用
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
console.log('桌面系统启动完成')
|
console.log('桌面系统启动完成')
|
||||||
|
})
|
||||||
} catch (error) {
|
.catch((error) => {
|
||||||
console.error('系统启动失败:', error)
|
console.error('系统启动失败:', error)
|
||||||
// 显示错误信息
|
// 显示错误信息
|
||||||
document.body.innerHTML = `
|
document.body.innerHTML = `
|
||||||
<div style="display: flex; justify-content: center; align-items: center; height: 100vh; font-family: sans-serif;">
|
<div style="display: flex; justify-content: center; align-items: center; height: 100vh; font-family: sans-serif;">
|
||||||
<div style="text-align: center; color: #e74c3c;">
|
<div style="text-align: center; color: #e74c3c;">
|
||||||
<h1>系统启动失败</h1>
|
<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 onclick="location.reload()" style="padding: 10px 20px; margin-top: 20px; cursor: pointer;">
|
||||||
重新加载
|
重新加载
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
// 启动应用
|
// 全局错误处理
|
||||||
startApplication()
|
app.config.errorHandler = (error, instance, info) => {
|
||||||
|
console.error('Vue应用错误:', error, info)
|
||||||
|
}
|
||||||
|
|
||||||
// 在页面卸载时清理系统服务
|
// 在页面卸载时清理系统服务
|
||||||
window.addEventListener('beforeunload', () => {
|
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 {
|
export class ApplicationSandboxEngine {
|
||||||
// 服务容器
|
|
||||||
private serviceContainer: IServiceContainer
|
|
||||||
|
|
||||||
private sandboxes = reactive(new Map<string, SandboxInstance>())
|
private sandboxes = reactive(new Map<string, SandboxInstance>())
|
||||||
private performanceData = reactive(new Map<string, SandboxPerformance[]>())
|
private performanceData = reactive(new Map<string, SandboxPerformance[]>())
|
||||||
private monitoringInterval: number | null = null
|
private monitoringInterval: number | null = null
|
||||||
|
|
||||||
// 资源服务
|
|
||||||
@Inject('resourceService')
|
|
||||||
private resourceService: ResourceService
|
private resourceService: ResourceService
|
||||||
|
|
||||||
constructor(resourceService: ResourceService, serviceContainer: IServiceContainer) {
|
constructor(resourceService: ResourceService) {
|
||||||
this.resourceService = resourceService
|
this.resourceService = resourceService
|
||||||
this.serviceContainer = serviceContainer
|
|
||||||
this.startPerformanceMonitoring()
|
this.startPerformanceMonitoring()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { reactive, ref } from 'vue'
|
import { reactive, ref } from 'vue'
|
||||||
|
import { EventBuilderImpl } from '@/events/impl/EventBuilderImpl'
|
||||||
import type { IEventBuilder, IEventMap, WindowFormDataUpdateParams } from '@/events/IEventBuilder'
|
import type { IEventBuilder, IEventMap, WindowFormDataUpdateParams } from '@/events/IEventBuilder'
|
||||||
import { ResourceService, ResourceType } from './ResourceService'
|
import type { ResourceType } from './ResourceService'
|
||||||
import { ServiceProvider, Inject } from './di/ServiceProvider'
|
|
||||||
import type { IServiceContainer } from './di/IServiceContainer'
|
// 导入所有服务
|
||||||
import { ServiceIds } from './di/ServiceRegistry'
|
import { WindowFormService } from './WindowFormService.ts'
|
||||||
import { WindowFormService } from './WindowFormService'
|
import { ResourceService } from './ResourceService'
|
||||||
import { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
|
import { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
|
||||||
import { ApplicationLifecycleManager } from './ApplicationLifecycleManager'
|
import { ApplicationLifecycleManager } from './ApplicationLifecycleManager'
|
||||||
import { externalAppDiscovery } from './ExternalAppDiscovery'
|
import { externalAppDiscovery } from './ExternalAppDiscovery'
|
||||||
@@ -54,24 +55,12 @@ export class SystemServiceIntegration {
|
|||||||
private config: SystemServiceConfig
|
private config: SystemServiceConfig
|
||||||
private startTime: Date
|
private startTime: Date
|
||||||
|
|
||||||
// 核心服务实例 - 使用依赖注入
|
// 核心服务实例
|
||||||
@Inject(ServiceIds.EVENT_BUILDER)
|
private eventBus: IEventBuilder<any>
|
||||||
private eventBus!: IEventBuilder<any>
|
private windowFormService!: WindowFormService
|
||||||
|
private resourceService!: ResourceService
|
||||||
@Inject(ServiceIds.WINDOW_FORM_SERVICE)
|
private sandboxEngine!: ApplicationSandboxEngine
|
||||||
private windowFormService!: any
|
private lifecycleManager!: ApplicationLifecycleManager
|
||||||
|
|
||||||
@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 systemStatus = reactive<SystemStatus>({
|
private systemStatus = reactive<SystemStatus>({
|
||||||
@@ -89,9 +78,8 @@ export class SystemServiceIntegration {
|
|||||||
// 性能监控
|
// 性能监控
|
||||||
private cleanupInterval: number | null = null
|
private cleanupInterval: number | null = null
|
||||||
private performanceInterval: number | null = null
|
private performanceInterval: number | null = null
|
||||||
private serviceContainer: IServiceContainer
|
|
||||||
|
|
||||||
constructor(serviceContainer: IServiceContainer, config: SystemServiceConfig = {}) {
|
constructor(config: SystemServiceConfig = {}) {
|
||||||
this.config = {
|
this.config = {
|
||||||
debug: false,
|
debug: false,
|
||||||
autoCleanup: true,
|
autoCleanup: true,
|
||||||
@@ -100,7 +88,7 @@ export class SystemServiceIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.startTime = new Date()
|
this.startTime = new Date()
|
||||||
this.serviceContainer = serviceContainer
|
this.eventBus = new EventBuilderImpl<any>()
|
||||||
|
|
||||||
this.setupGlobalErrorHandling()
|
this.setupGlobalErrorHandling()
|
||||||
}
|
}
|
||||||
@@ -110,31 +98,36 @@ export class SystemServiceIntegration {
|
|||||||
*/
|
*/
|
||||||
public async initialize(): Promise<void> {
|
public async initialize(): Promise<void> {
|
||||||
if (this.initialized.value) {
|
if (this.initialized.value) {
|
||||||
console.warn('系统服务已经初始化')
|
throw new Error('系统服务已初始化')
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('开始初始化系统服务...')
|
console.log('开始初始化系统服务...')
|
||||||
|
|
||||||
// 启动自动清理(如果启用)
|
// 按依赖顺序初始化服务
|
||||||
|
await this.initializeServices()
|
||||||
|
|
||||||
|
// 设置服务间通信
|
||||||
|
this.setupServiceCommunication()
|
||||||
|
|
||||||
|
// 设置SDK消息处理
|
||||||
|
this.setupSDKMessageHandling()
|
||||||
|
|
||||||
|
// 启动自动清理
|
||||||
if (this.config.autoCleanup) {
|
if (this.config.autoCleanup) {
|
||||||
this.startAutoCleanup()
|
this.startAutoCleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新系统状态
|
// 启动外置应用发现服务
|
||||||
this.systemStatus.initialized = true
|
// 注意:外置应用发现服务统一由 SystemServiceIntegration 管理,
|
||||||
this.systemStatus.running = true
|
// ApplicationLifecycleManager 只负责使用已发现的应用,避免重复启动
|
||||||
|
console.log('启动外置应用发现服务...')
|
||||||
|
await externalAppDiscovery.startDiscovery()
|
||||||
|
|
||||||
this.initialized.value = true
|
this.initialized.value = true
|
||||||
this.running.value = true
|
this.running.value = true
|
||||||
|
this.systemStatus.initialized = true
|
||||||
// 标记所有服务状态为已启动
|
this.systemStatus.running = true
|
||||||
this.systemStatus.servicesStatus = {
|
|
||||||
windowFormService: true,
|
|
||||||
resourceService: true,
|
|
||||||
sandboxEngine: true,
|
|
||||||
lifecycleManager: true
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('系统服务初始化完成')
|
console.log('系统服务初始化完成')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -144,8 +137,6 @@ export class SystemServiceIntegration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... 保留其他现有方法
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统状态
|
* 获取系统状态
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"strict": true, // 严格模式检查
|
"strict": true, // 严格模式检查
|
||||||
"experimentalDecorators": true, // 装饰器
|
"experimentalDecorators": true, // 装饰器
|
||||||
"emitDecoratorMetadata": true, // 元数据反射
|
|
||||||
"useDefineForClassFields": false,
|
"useDefineForClassFields": false,
|
||||||
"strictPropertyInitialization": false, // 严格属性初始化检查
|
"strictPropertyInitialization": false, // 严格属性初始化检查
|
||||||
"noUnusedLocals": false, // 检查未使用的局部变量
|
"noUnusedLocals": false, // 检查未使用的局部变量
|
||||||
|
|||||||
Reference in New Issue
Block a user