2025-08-19 14:56:38 +08:00
|
|
|
|
import { v4 as uuidV4 } from 'uuid';
|
2025-08-28 08:05:16 +08:00
|
|
|
|
import WindowFormImpl from '../../window/impl/WindowFormImpl.ts'
|
2025-08-26 10:33:41 +08:00
|
|
|
|
import type { IProcess } from '@/core/process/IProcess.ts'
|
|
|
|
|
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
2025-08-28 08:05:16 +08:00
|
|
|
|
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
2025-08-29 14:22:20 +08:00
|
|
|
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
2025-09-09 12:03:09 +08:00
|
|
|
|
import { EventBuilderImpl } from '@/core/events/impl/EventBuilderImpl.ts'
|
|
|
|
|
|
import type { IEventBuilder } from '@/core/events/IEventBuilder.ts'
|
|
|
|
|
|
import type { IProcessEvent } from '@/core/process/types/ProcessEvent.ts'
|
2025-08-19 14:56:38 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 进程
|
|
|
|
|
|
*/
|
2025-08-26 10:33:41 +08:00
|
|
|
|
export default class ProcessImpl implements IProcess {
|
2025-08-19 14:56:38 +08:00
|
|
|
|
private readonly _id: string = uuidV4();
|
2025-08-26 10:33:41 +08:00
|
|
|
|
private readonly _processInfo: IProcessInfo;
|
2025-08-19 14:56:38 +08:00
|
|
|
|
// 当前进程的窗体集合
|
2025-08-28 08:05:16 +08:00
|
|
|
|
private _windowForms: Map<string, IWindowForm> = new Map();
|
2025-09-09 12:03:09 +08:00
|
|
|
|
private _event: IEventBuilder<IProcessEvent> = new EventBuilderImpl<IProcessEvent>()
|
2025-08-19 14:56:38 +08:00
|
|
|
|
|
|
|
|
|
|
public get id() {
|
|
|
|
|
|
return this._id;
|
|
|
|
|
|
}
|
|
|
|
|
|
public get processInfo() {
|
|
|
|
|
|
return this._processInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
public get windowForms() {
|
|
|
|
|
|
return this._windowForms;
|
|
|
|
|
|
}
|
2025-09-09 12:03:09 +08:00
|
|
|
|
public get event() {
|
|
|
|
|
|
return this._event;
|
|
|
|
|
|
}
|
2025-08-19 14:56:38 +08:00
|
|
|
|
|
2025-08-26 10:33:41 +08:00
|
|
|
|
constructor(info: IProcessInfo) {
|
2025-08-19 14:56:38 +08:00
|
|
|
|
console.log(`AppProcess: ${info.name}`)
|
|
|
|
|
|
this._processInfo = info;
|
|
|
|
|
|
|
|
|
|
|
|
const startName = info.startName;
|
|
|
|
|
|
|
2025-09-09 12:03:09 +08:00
|
|
|
|
this.initEvent();
|
|
|
|
|
|
|
2025-08-29 14:22:20 +08:00
|
|
|
|
processManager.registerProcess(this);
|
2025-08-19 14:56:38 +08:00
|
|
|
|
// 通过设置 isJustProcess 为 true,则不会创建窗体
|
|
|
|
|
|
if (!info.isJustProcess) {
|
|
|
|
|
|
this.openWindowForm(startName)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-09 12:03:09 +08:00
|
|
|
|
private initEvent() {
|
|
|
|
|
|
this.event.addEventListener('onProcessWindowFormExit', (id: string) => {
|
|
|
|
|
|
this.windowForms.delete(id)
|
|
|
|
|
|
if(this.windowForms.size === 0) {
|
|
|
|
|
|
processManager.removeProcess(this)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-19 14:56:38 +08:00
|
|
|
|
public openWindowForm(startName: string) {
|
2025-08-28 08:05:16 +08:00
|
|
|
|
const info = this._processInfo.windowFormConfigs.find(item => item.name === startName);
|
|
|
|
|
|
if (!info) throw new Error(`未找到窗体:${startName}`);
|
|
|
|
|
|
const window = new WindowFormImpl(this, info);
|
2025-08-19 14:56:38 +08:00
|
|
|
|
this._windowForms.set(window.id, window);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|