1
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { reactive } from 'vue'
|
||||
import type { WindowService } from './WindowService'
|
||||
import type { ResourceService } from './ResourceService'
|
||||
import type { EventCommunicationService } from './EventCommunicationService'
|
||||
import type { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { externalAppDiscovery } from './ExternalAppDiscovery'
|
||||
@@ -121,21 +120,16 @@ export class ApplicationLifecycleManager {
|
||||
|
||||
private windowService: WindowService
|
||||
private resourceService: ResourceService
|
||||
private eventService: EventCommunicationService
|
||||
private sandboxEngine: ApplicationSandboxEngine
|
||||
|
||||
constructor(
|
||||
windowService: WindowService,
|
||||
resourceService: ResourceService,
|
||||
eventService: EventCommunicationService,
|
||||
sandboxEngine: ApplicationSandboxEngine
|
||||
) {
|
||||
this.windowService = windowService
|
||||
this.resourceService = resourceService
|
||||
this.eventService = eventService
|
||||
this.sandboxEngine = sandboxEngine
|
||||
|
||||
this.setupEventListeners()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,49 +379,6 @@ export class ApplicationLifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
// 私有方法
|
||||
|
||||
/**
|
||||
* 为内置应用挂载 AppRenderer 组件
|
||||
*/
|
||||
private async mountBuiltInApp(appId: string, windowInstance: any): Promise<void> {
|
||||
try {
|
||||
// 动态导入 Vue 和 AppRenderer
|
||||
const { createApp } = await import('vue')
|
||||
const AppRenderer = (await import('../ui/components/AppRenderer.vue')).default
|
||||
|
||||
console.log(`[LifecycleManager] 为内置应用 ${appId} 创建 AppRenderer 组件`)
|
||||
|
||||
console.log('----------------------------------')
|
||||
|
||||
const app = createApp({
|
||||
components: { AppRenderer },
|
||||
template: `<AppRenderer :app-id="'${appId}'" :window-id="'${windowInstance.id}'"/>`
|
||||
})
|
||||
|
||||
// 提供系统服务(使用当前实例所在的系统服务)
|
||||
app.provide('systemService', {
|
||||
getWindowService: () => this.windowService,
|
||||
getResourceService: () => this.resourceService,
|
||||
getEventService: () => this.eventService,
|
||||
getSandboxEngine: () => this.sandboxEngine,
|
||||
getLifecycleManager: () => this
|
||||
})
|
||||
|
||||
// 挂载到窗口内容区域
|
||||
const contentArea = windowInstance.element?.querySelector('.window-content')
|
||||
if (contentArea) {
|
||||
app.mount(contentArea)
|
||||
console.log(`[LifecycleManager] AppRenderer 组件已挂载到窗口 ${windowInstance.id}`)
|
||||
} else {
|
||||
throw new Error('未找到窗口内容区域')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`内置应用 ${appId} 挂载失败:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查权限
|
||||
*/
|
||||
@@ -510,28 +461,6 @@ export class ApplicationLifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置事件监听器
|
||||
*/
|
||||
private setupEventListeners(): void {
|
||||
// 监听沙箱状态变化
|
||||
this.eventService.subscribe('system', 'sandbox-state-change', (message) => {
|
||||
const { sandboxId, newState } = message.payload
|
||||
|
||||
// 查找对应的应用
|
||||
for (const app of this.installedApps.values()) {
|
||||
if (app.sandboxId === sandboxId) {
|
||||
if (newState === 'error') {
|
||||
this.handleAppError(app.id, new Error('沙箱错误'))
|
||||
} else if (newState === 'destroyed') {
|
||||
this.handleAppCrash(app.id, '沙箱被销毁')
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理应用错误
|
||||
*/
|
||||
@@ -541,12 +470,6 @@ export class ApplicationLifecycleManager {
|
||||
|
||||
app.errorCount++
|
||||
|
||||
this.eventService.sendMessage('system', 'app-lifecycle', {
|
||||
type: 'error',
|
||||
appId,
|
||||
error: error.message
|
||||
})
|
||||
|
||||
console.error(`应用 ${appId} 发生错误:`, error)
|
||||
}
|
||||
|
||||
@@ -577,11 +500,12 @@ export class ApplicationLifecycleManager {
|
||||
const oldState = app.state
|
||||
app.state = newState
|
||||
|
||||
this.eventService.sendMessage('system', 'app-lifecycle', {
|
||||
type: 'stateChanged',
|
||||
appId: app.id,
|
||||
newState,
|
||||
oldState
|
||||
})
|
||||
// 移除事件服务消息发送
|
||||
// this.eventService.sendMessage('system', 'app-lifecycle', {
|
||||
// type: 'stateChanged',
|
||||
// appId: app.id,
|
||||
// newState,
|
||||
// oldState
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user