This commit is contained in:
2025-10-10 10:37:11 +08:00
parent 05882bb3d3
commit 0ca5daad3b
12 changed files with 58 additions and 58 deletions

View File

@@ -56,7 +56,7 @@ Vue Desktop 使用分层的事件管理系统:
```mermaid ```mermaid
graph TD graph TD
A[SystemServiceIntegration] --> B[EventCommunicationService] A[SystemServiceIntegration] --> B[EventCommunicationService]
A --> C[WindowService] A --> C[WindowFormService]
A --> D[ResourceService] A --> D[ResourceService]
B --> E[IEventBuilder] B --> E[IEventBuilder]
@@ -114,7 +114,7 @@ constructor(config: SystemServiceConfig = {}) {
// 注入到依赖的服务中 // 注入到依赖的服务中
// EventCommunicationService 需要 IEventBuilder 接口 // EventCommunicationService 需要 IEventBuilder 接口
// WindowService 也需要 IEventBuilder 接口 // WindowFormService 也需要 IEventBuilder 接口
} }
``` ```

View File

@@ -17,7 +17,7 @@ graph TD
A --> D[事件系统] A --> D[事件系统]
A --> E[应用注册中心] A --> E[应用注册中心]
B --> B1[WindowService] B --> B1[WindowFormService]
B --> B2[ResourceService] B --> B2[ResourceService]
B --> B3[EventCommunicationService] B --> B3[EventCommunicationService]
B --> B4[ApplicationSandboxEngine] B --> B4[ApplicationSandboxEngine]
@@ -39,7 +39,7 @@ graph TD
| 模块 | 职责 | | 模块 | 职责 |
| --------------------------- | ---------------------------------- | | --------------------------- | ---------------------------------- |
| WindowService | 管理应用窗体的创建、销毁、状态控制 | | WindowFormService | 管理应用窗体的创建、销毁、状态控制 |
| ResourceService | 管理应用资源访问权限和存储 | | ResourceService | 管理应用资源访问权限和存储 |
| EventCommunicationService | 处理应用间通信 | | EventCommunicationService | 处理应用间通信 |
| ApplicationSandboxEngine | 为外部应用创建安全沙箱环境 | | ApplicationSandboxEngine | 为外部应用创建安全沙箱环境 |

View File

@@ -26,7 +26,7 @@ graph TB
end end
subgraph "系统服务层" subgraph "系统服务层"
WindowService[窗体服务] WindowFormService[窗体服务]
ResourceService[资源服务] ResourceService[资源服务]
EventService[事件服务] EventService[事件服务]
SecurityService[安全服务] SecurityService[安全服务]
@@ -47,7 +47,7 @@ graph TB
end end
Desktop --> WindowManager Desktop --> WindowManager
WindowManager --> WindowService WindowManager --> WindowFormService
AppContainer --> SandboxEngine AppContainer --> SandboxEngine
SDKBridge --> SystemService[系统服务层] SDKBridge --> SystemService[系统服务层]
App1 --> AppContainer App1 --> AppContainer

View File

@@ -3,7 +3,7 @@
<cite> <cite>
**本文档引用文件** **本文档引用文件**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts)
- [WindowService.ts](file://src/services/WindowService.ts) - [WindowFormService.ts](file://src/services/WindowFormService.ts)
</cite> </cite>
## 目录 ## 目录
@@ -16,11 +16,11 @@
`windowFormCreated` 事件在新窗口实例成功挂载并完成首次渲染后触发,标志着窗口已完全初始化并可交互。该事件不携带任何参数,作为全局窗口创建完成的信号。 `windowFormCreated` 事件在新窗口实例成功挂载并完成首次渲染后触发,标志着窗口已完全初始化并可交互。该事件不携带任何参数,作为全局窗口创建完成的信号。
根据 `WindowFormEventManager.ts` 中的定义,此事件是 `IWindowFormEvent` 接口的一部分,由 `wfem` 事件管理器负责分发。虽然当前实现中未直接显示触发逻辑,但结合 `WindowService.ts` 的窗口创建流程可知,该事件应在 `createWindow` 方法执行完毕、DOM 元素已添加至页面且应用内容加载完成后被通知。 根据 `WindowFormEventManager.ts` 中的定义,此事件是 `IWindowFormEvent` 接口的一部分,由 `wfem` 事件管理器负责分发。虽然当前实现中未直接显示触发逻辑,但结合 `WindowFormService.ts` 的窗口创建流程可知,该事件应在 `createWindow` 方法执行完毕、DOM 元素已添加至页面且应用内容加载完成后被通知。
**Section sources** **Section sources**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41)
- [WindowService.ts](file://src/services/WindowService.ts#L83-L118) - [WindowFormService.ts](file://src/services/WindowService.ts#L83-L118)
## 应用场景分析 ## 应用场景分析
@@ -35,7 +35,7 @@
**Section sources** **Section sources**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41)
- [WindowService.ts](file://src/services/WindowService.ts#L83-L118) - [WindowFormService.ts](file://src/services/WindowService.ts#L83-L118)
## 事件监听代码范例 ## 事件监听代码范例
@@ -58,7 +58,7 @@ wfem.addEventListener('windowFormCreated', () => {
**Section sources** **Section sources**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L60-L60) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L60-L60)
- [WindowService.ts](file://src/services/WindowService.ts#L83-L118) - [WindowFormService.ts](file://src/services/WindowService.ts#L83-L118)
## 生命周期时序关系 ## 生命周期时序关系
@@ -73,4 +73,4 @@ wfem.addEventListener('windowFormCreated', () => {
**Section sources** **Section sources**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L41-L41)
- [WindowService.ts](file://src/services/WindowService.ts#L83-L118) - [WindowFormService.ts](file://src/services/WindowService.ts#L83-L118)

View File

@@ -3,7 +3,7 @@
<cite> <cite>
**本文档引用文件** **本文档引用文件**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts)
- [WindowService.ts](file://src/services/WindowService.ts) - [WindowFormService.ts](file://src/services/WindowFormService.ts)
- [WindowFormTypes.ts](file://src/ui/types/WindowFormTypes.ts) - [WindowFormTypes.ts](file://src/ui/types/WindowFormTypes.ts)
</cite> </cite>
@@ -73,14 +73,14 @@ I --> J[接收端更新UI]
``` ```
**Diagram sources** **Diagram sources**
- [WindowService.ts](file://src/services/WindowService.ts#L512-L552) - [WindowFormService.ts](file://src/services/WindowService.ts#L512-L552)
- [WindowService.ts](file://src/services/WindowService.ts#L248-L304) - [WindowFormService.ts](file://src/services/WindowService.ts#L248-L304)
- [WindowService.ts](file://src/services/WindowService.ts#L179-L213) - [WindowFormService.ts](file://src/services/WindowService.ts#L179-L213)
**Section sources** **Section sources**
- [WindowService.ts](file://src/services/WindowService.ts#L512-L552) - [WindowFormService.ts](file://src/services/WindowService.ts#L512-L552)
- [WindowService.ts](file://src/services/WindowService.ts#L248-L304) - [WindowFormService.ts](file://src/services/WindowService.ts#L248-L304)
- [WindowService.ts](file://src/services/WindowService.ts#L179-L213) - [WindowFormService.ts](file://src/services/WindowService.ts#L179-L213)
## 接收端批量更新UI的TypeScript示例 ## 接收端批量更新UI的TypeScript示例
接收 `windowFormDataUpdate` 事件后应使用接收到的完整数据对象一次性批量更新UI避免逐个属性设置带来的性能开销和视觉闪烁。以下为推荐的处理方式 接收 `windowFormDataUpdate` 事件后应使用接收到的完整数据对象一次性批量更新UI避免逐个属性设置带来的性能开销和视觉闪烁。以下为推荐的处理方式
@@ -146,4 +146,4 @@ wfem.addEventListener('windowFormDataUpdate', debouncedHandler);
**Section sources** **Section sources**
- [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L37-L37) - [WindowFormEventManager.ts](file://src/events/WindowFormEventManager.ts#L37-L37)
- [WindowService.ts](file://src/services/WindowService.ts#L67-L118) - [WindowFormService.ts](file://src/services/WindowService.ts#L67-L118)

View File

@@ -17,7 +17,7 @@
### 核心服务层 ### 核心服务层
- **[WindowService](./src/services/WindowService.ts)** - 窗体管理服务,支持完整的窗体生命周期 - **[WindowFormService](src/services/WindowFormService.ts)** - 窗体管理服务,支持完整的窗体生命周期
- **[ResourceService](./src/services/ResourceService.ts)** - 资源管理服务,提供权限控制和资源访问 - **[ResourceService](./src/services/ResourceService.ts)** - 资源管理服务,提供权限控制和资源访问
- **[ApplicationSandboxEngine](./src/services/ApplicationSandboxEngine.ts)** - 应用沙箱引擎,多层安全隔离 - **[ApplicationSandboxEngine](./src/services/ApplicationSandboxEngine.ts)** - 应用沙箱引擎,多层安全隔离
- **[ApplicationLifecycleManager](./src/services/ApplicationLifecycleManager.ts)** - 应用生命周期管理 - **[ApplicationLifecycleManager](./src/services/ApplicationLifecycleManager.ts)** - 应用生命周期管理
@@ -89,7 +89,7 @@
│ │ ├── ExternalAppDiscovery.ts │ │ ├── ExternalAppDiscovery.ts
│ │ ├── ResourceService.ts │ │ ├── ResourceService.ts
│ │ ├── SystemServiceIntegration.ts │ │ ├── SystemServiceIntegration.ts
│ │ └── WindowService.ts │ │ └── WindowFormService.ts
│ ├── stores │ ├── stores
│ │ └── counter.ts │ │ └── counter.ts
│ ├── ui │ ├── ui
@@ -178,7 +178,7 @@ const systemService = inject<SystemServiceIntegration>('systemService')
可用服务: 可用服务:
- `getWindowService()` - 窗体服务 - `getWindowFormService()` - 窗体服务
- `getResourceService()` - 资源服务 - `getResourceService()` - 资源服务
- `getSandboxEngine()` - 沙箱引擎 - `getSandboxEngine()` - 沙箱引擎
- `getLifecycleManager()` - 生命周期管理器 - `getLifecycleManager()` - 生命周期管理器

View File

@@ -1,5 +1,5 @@
import type { IDestroyable } from '@/common/types/IDestroyable' import type { IDestroyable } from '@/common/types/IDestroyable'
import type { WindowState } from '@/services/WindowService' import type { WindowState } from '@/services/WindowFormService.ts'
import type { ResourceType } from '@/services/ResourceService' import type { ResourceType } from '@/services/ResourceService'
/** /**

View File

@@ -1,9 +1,9 @@
import { reactive } from 'vue' import { reactive } from 'vue'
import type { WindowService } from './WindowService'
import type { ResourceService } from './ResourceService' import type { ResourceService } from './ResourceService'
import type { ApplicationSandboxEngine } from './ApplicationSandboxEngine' import type { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { externalAppDiscovery } from './ExternalAppDiscovery' import { externalAppDiscovery } from './ExternalAppDiscovery'
import type { WindowFormService } from '@/services/WindowFormService.ts'
/** /**
* 应用状态枚举 * 应用状态枚举
@@ -118,16 +118,16 @@ export class ApplicationLifecycleManager {
private runningProcesses = reactive(new Map<string, AppInstance>()) private runningProcesses = reactive(new Map<string, AppInstance>())
private appFiles = new Map<string, Map<string, Blob | string>>() // 应用文件存储 private appFiles = new Map<string, Map<string, Blob | string>>() // 应用文件存储
private windowService: WindowService private windowFormService: WindowFormService
private resourceService: ResourceService private resourceService: ResourceService
private sandboxEngine: ApplicationSandboxEngine private sandboxEngine: ApplicationSandboxEngine
constructor( constructor(
windowService: WindowService, windowFormService: WindowFormService,
resourceService: ResourceService, resourceService: ResourceService,
sandboxEngine: ApplicationSandboxEngine sandboxEngine: ApplicationSandboxEngine
) { ) {
this.windowService = windowService this.windowFormService = windowFormService
this.resourceService = resourceService this.resourceService = resourceService
this.sandboxEngine = sandboxEngine this.sandboxEngine = sandboxEngine
} }
@@ -200,7 +200,7 @@ export class ApplicationLifecycleManager {
maxHeight: app.manifest.window?.maxHeight maxHeight: app.manifest.window?.maxHeight
} }
const windowInstance = await this.windowService.createWindow(appId, windowConfig) const windowInstance = await this.windowFormService.createWindow(appId, windowConfig)
windowId = windowInstance.id windowId = windowInstance.id
app.windowId = windowId app.windowId = windowId
} }
@@ -292,9 +292,9 @@ export class ApplicationLifecycleManager {
// 关闭窗体(如果还存在) // 关闭窗体(如果还存在)
if (app.windowId) { if (app.windowId) {
const window = this.windowService.getWindow(app.windowId) const window = this.windowFormService.getWindow(app.windowId)
if (window) { if (window) {
await this.windowService.destroyWindow(app.windowId) await this.windowFormService.destroyWindow(app.windowId)
} }
app.windowId = undefined app.windowId = undefined
} }

View File

@@ -4,7 +4,7 @@ import type { IEventBuilder, IEventMap, WindowFormDataUpdateParams } from '@/eve
import type { ResourceType } from './ResourceService' import type { ResourceType } from './ResourceService'
// 导入所有服务 // 导入所有服务
import { WindowService } from './WindowService' import { WindowFormService } from './WindowFormService.ts'
import { ResourceService } from './ResourceService' import { ResourceService } from './ResourceService'
import { ApplicationSandboxEngine } from './ApplicationSandboxEngine' import { ApplicationSandboxEngine } from './ApplicationSandboxEngine'
import { ApplicationLifecycleManager } from './ApplicationLifecycleManager' import { ApplicationLifecycleManager } from './ApplicationLifecycleManager'
@@ -26,7 +26,7 @@ export interface SystemStatus {
initialized: boolean // 系统是否初始化完成 initialized: boolean // 系统是否初始化完成
running: boolean // 系统是否运行中 running: boolean // 系统是否运行中
servicesStatus: { servicesStatus: {
windowService: boolean // 窗体服务是否启动 windowFormService: boolean // 窗体服务是否启动
resourceService: boolean // 资源服务是否启动 resourceService: boolean // 资源服务是否启动
sandboxEngine: boolean // 沙箱引擎是否启动 sandboxEngine: boolean // 沙箱引擎是否启动
lifecycleManager: boolean // 生命周期管理器是否启动 lifecycleManager: boolean // 生命周期管理器是否启动
@@ -57,7 +57,7 @@ export class SystemServiceIntegration {
// 核心服务实例 // 核心服务实例
private eventBus: IEventBuilder<any> private eventBus: IEventBuilder<any>
private windowService!: WindowService private windowFormService!: WindowFormService
private resourceService!: ResourceService private resourceService!: ResourceService
private sandboxEngine!: ApplicationSandboxEngine private sandboxEngine!: ApplicationSandboxEngine
private lifecycleManager!: ApplicationLifecycleManager private lifecycleManager!: ApplicationLifecycleManager
@@ -67,7 +67,7 @@ export class SystemServiceIntegration {
initialized: false, initialized: false,
running: false, running: false,
servicesStatus: { servicesStatus: {
windowService: false, windowFormService: false,
resourceService: false, resourceService: false,
sandboxEngine: false, sandboxEngine: false,
lifecycleManager: false lifecycleManager: false
@@ -96,7 +96,7 @@ export class SystemServiceIntegration {
/** /**
* 初始化系统服务 * 初始化系统服务
*/ */
private async initialize(): Promise<void> { public async initialize(): Promise<void> {
if (this.initialized.value) { if (this.initialized.value) {
throw new Error('系统服务已初始化') throw new Error('系统服务已初始化')
} }
@@ -147,9 +147,9 @@ export class SystemServiceIntegration {
/** /**
* 获取窗体服务 * 获取窗体服务
*/ */
getWindowService(): WindowService { getWindowFormService(): WindowFormService {
this.checkInitialized() this.checkInitialized()
return this.windowService return this.windowFormService
} }
/** /**
@@ -221,7 +221,7 @@ export class SystemServiceIntegration {
/** /**
* 关闭系统服务 * 关闭系统服务
*/ */
private async shutdown(): Promise<void> { public async shutdown(): Promise<void> {
console.log('关闭系统服务...') console.log('关闭系统服务...')
this.running.value = false this.running.value = false
@@ -255,11 +255,11 @@ export class SystemServiceIntegration {
this.sandboxEngine.destroy() this.sandboxEngine.destroy()
} }
if (this.windowService) { if (this.windowFormService) {
// 关闭所有窗体 // 关闭所有窗体
const windows = this.windowService.getAllWindows() const windows = this.windowFormService.getAllWindows()
for (const window of windows) { for (const window of windows) {
await this.windowService.destroyWindow(window.id) await this.windowFormService.destroyWindow(window.id)
} }
} }
} catch (error) { } catch (error) {
@@ -283,8 +283,8 @@ export class SystemServiceIntegration {
// 3. 初始化窗体服务 // 3. 初始化窗体服务
console.log('初始化窗体服务...') console.log('初始化窗体服务...')
this.windowService = new WindowService(this.eventBus) this.windowFormService = new WindowFormService(this.eventBus)
this.systemStatus.servicesStatus.windowService = true this.systemStatus.servicesStatus.windowFormService = true
// 4. 初始化沙箱引擎 // 4. 初始化沙箱引擎
console.log('初始化沙箱引擎...') console.log('初始化沙箱引擎...')
@@ -294,7 +294,7 @@ export class SystemServiceIntegration {
// 5. 初始化生命周期管理器 // 5. 初始化生命周期管理器
console.log('初始化生命周期管理器...') console.log('初始化生命周期管理器...')
this.lifecycleManager = new ApplicationLifecycleManager( this.lifecycleManager = new ApplicationLifecycleManager(
this.windowService, this.windowFormService,
this.resourceService, this.resourceService,
this.sandboxEngine this.sandboxEngine
) )
@@ -305,7 +305,7 @@ export class SystemServiceIntegration {
* 设置服务间通信 * 设置服务间通信
*/ */
private setupServiceCommunication(): void { private setupServiceCommunication(): void {
// 监听窗体状态变化(来自 WindowService 的 onStateChange 事件) // 监听窗体状态变化(来自 windowFormService 的 onStateChange 事件)
this.eventBus.addEventListener( this.eventBus.addEventListener(
'onWindowStateChanged', 'onWindowStateChanged',
(windowId: string, newState: string, oldState: string) => { (windowId: string, newState: string, oldState: string) => {
@@ -504,14 +504,14 @@ export class SystemServiceIntegration {
switch (action) { switch (action) {
case 'setTitle': case 'setTitle':
return this.windowService.setWindowTitle(windowId, data.title) return this.windowFormService.setWindowTitle(windowId, data.title)
case 'resize': case 'resize':
return this.windowService.setWindowSize(windowId, data.width, data.height) return this.windowFormService.setWindowSize(windowId, data.width, data.height)
case 'move': case 'move':
// 实现窗体移动功能 // 实现窗体移动功能
const window = this.windowService.getWindow(windowId) const window = this.windowFormService.getWindow(windowId)
if (window && window.element) { if (window && window.element) {
// 更新窗体位置 // 更新窗体位置
window.config.x = data.x window.config.x = data.x
@@ -524,23 +524,23 @@ export class SystemServiceIntegration {
return false return false
case 'minimize': case 'minimize':
return this.windowService.minimizeWindow(windowId) return this.windowFormService.minimizeWindow(windowId)
case 'maximize': case 'maximize':
return this.windowService.maximizeWindow(windowId) return this.windowFormService.maximizeWindow(windowId)
case 'restore': case 'restore':
return this.windowService.restoreWindow(windowId) return this.windowFormService.restoreWindow(windowId)
case 'close': case 'close':
return this.lifecycleManager.stopApp(appId) return this.lifecycleManager.stopApp(appId)
case 'getState': case 'getState':
const windowInfo = this.windowService.getWindow(windowId) const windowInfo = this.windowFormService.getWindow(windowId)
return windowInfo?.state return windowInfo?.state
case 'getSize': case 'getSize':
const windowData = this.windowService.getWindow(windowId) const windowData = this.windowFormService.getWindow(windowId)
return { return {
width: windowData?.config.width, width: windowData?.config.width,
height: windowData?.config.height height: windowData?.config.height

View File

@@ -157,7 +157,7 @@ export interface WindowEvents extends IEventMap {
/** /**
* 窗体管理服务类 * 窗体管理服务类
*/ */
export class WindowService { export class WindowFormService {
private windows = reactive(new Map<string, WindowInstance>()) private windows = reactive(new Map<string, WindowInstance>())
private activeWindowId = ref<string | null>(null) private activeWindowId = ref<string | null>(null)
private nextZIndex = 1000 private nextZIndex = 1000

View File

@@ -78,7 +78,7 @@ const closeWindow = (windowId: string) => {
// 通知系统服务关闭窗口 // 通知系统服务关闭窗口
if (systemService) { if (systemService) {
const windowService = systemService.getWindowService() const windowService = systemService.getWindowFormService()
windowService.destroyWindow(windowId) windowService.destroyWindow(windowId)
} }
} }

View File

@@ -50,7 +50,7 @@ const systemStatus = ref<SystemStatus>({
initialized: false, initialized: false,
running: false, running: false,
servicesStatus: { servicesStatus: {
windowService: false, windowFormService: false,
resourceService: false, resourceService: false,
sandboxEngine: false, sandboxEngine: false,
lifecycleManager: false lifecycleManager: false
@@ -111,7 +111,7 @@ const startApp = async (appId: string) => {
} }
// 创建窗口 // 创建窗口
const windowService = systemService.getWindowService() const windowService = systemService.getWindowFormService()
const windowConfig = { const windowConfig = {
title: appRegistration.manifest.name, title: appRegistration.manifest.name,
width: appRegistration.manifest.window.width, width: appRegistration.manifest.window.width,