保存一下
This commit is contained in:
43
src/core/process/impl/ProcessImpl.ts
Normal file
43
src/core/process/impl/ProcessImpl.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import XSystem from '../../XSystem.ts'
|
||||
import WindowForm from '../../window/WindowForm.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
|
||||
/**
|
||||
* 进程
|
||||
*/
|
||||
export default class ProcessImpl implements IProcess {
|
||||
private readonly _id: string = uuidV4();
|
||||
private readonly _processInfo: IProcessInfo;
|
||||
// 当前进程的窗体集合
|
||||
private _windowForms: Map<string, WindowForm> = new Map();
|
||||
|
||||
public get id() {
|
||||
return this._id;
|
||||
}
|
||||
public get processInfo() {
|
||||
return this._processInfo;
|
||||
}
|
||||
public get windowForms() {
|
||||
return this._windowForms;
|
||||
}
|
||||
|
||||
constructor(info: IProcessInfo) {
|
||||
console.log(`AppProcess: ${info.name}`)
|
||||
this._processInfo = info;
|
||||
|
||||
const startName = info.startName;
|
||||
|
||||
XSystem.instance.processManage.addProcess(this);
|
||||
// 通过设置 isJustProcess 为 true,则不会创建窗体
|
||||
if (!info.isJustProcess) {
|
||||
this.openWindowForm(startName)
|
||||
}
|
||||
}
|
||||
|
||||
public openWindowForm(startName: string) {
|
||||
const window = new WindowForm(this, startName);
|
||||
this._windowForms.set(window.id, window);
|
||||
}
|
||||
}
|
||||
101
src/core/process/impl/ProcessInfoImpl.ts
Normal file
101
src/core/process/impl/ProcessInfoImpl.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import type { IVersion } from '../../common/types/IVersion.ts'
|
||||
import type { IAppProcessInfoParams } from '../types/IAppProcessInfoParams.ts'
|
||||
import type { IWindowFormConfig } from '../../window/types/IWindowFormConfig.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
|
||||
export class ProcessInfoImpl implements IProcessInfo {
|
||||
/**
|
||||
* 应用进程名称
|
||||
* @private
|
||||
*/
|
||||
private readonly _name: string;
|
||||
|
||||
/**
|
||||
* 应用进程标题
|
||||
* @private
|
||||
*/
|
||||
private readonly _title: string;
|
||||
|
||||
/**
|
||||
* 应用进程描述
|
||||
* @private
|
||||
*/
|
||||
private readonly _description: string;
|
||||
|
||||
/**
|
||||
* 应用进程图标
|
||||
* @private
|
||||
*/
|
||||
private readonly _icon: string;
|
||||
|
||||
/**
|
||||
* 应用进程启动入口
|
||||
* 对应windowFrom参数name
|
||||
* @private
|
||||
*/
|
||||
private readonly _startName: string;
|
||||
|
||||
/**
|
||||
* 应用版本信息
|
||||
* @private
|
||||
*/
|
||||
private readonly _version: IVersion;
|
||||
|
||||
/**
|
||||
* 应用是否只存在一个进程
|
||||
* @private
|
||||
*/
|
||||
private readonly _singleton: boolean;
|
||||
|
||||
/**
|
||||
* 是否只是一个进程
|
||||
* @private
|
||||
*/
|
||||
private readonly _isJustProcess: boolean;
|
||||
|
||||
/**
|
||||
* 进程所有的窗口配置信息
|
||||
* @private
|
||||
*/
|
||||
private readonly _windowFormConfigs: Array<IWindowFormConfig>;
|
||||
|
||||
constructor(info: IAppProcessInfoParams) {
|
||||
this._name = info.name;
|
||||
this._title = info.title || '';
|
||||
this._description = info.description || '';
|
||||
this._icon = <string> info.icon;
|
||||
this._startName = info.startName || '';
|
||||
this._version = info.version || { company: 'XZG', major: 1, minor: 0, build: 0, private: 0 };
|
||||
this._singleton = info.singleton;
|
||||
this._isJustProcess = info.isJustProcess;
|
||||
this._windowFormConfigs = info.windowFormConfigs || [];
|
||||
}
|
||||
|
||||
public get name() {
|
||||
return this._name;
|
||||
}
|
||||
public get title() {
|
||||
return this._title;
|
||||
}
|
||||
public get description() {
|
||||
return this._description;
|
||||
}
|
||||
public get icon() {
|
||||
return this._icon;
|
||||
}
|
||||
public get startName() {
|
||||
return this._startName;
|
||||
}
|
||||
public get version() {
|
||||
return this._version;
|
||||
}
|
||||
public get singleton() {
|
||||
return this._singleton;
|
||||
}
|
||||
public get isJustProcess() {
|
||||
return this._isJustProcess;
|
||||
}
|
||||
public get windowFormConfigs() {
|
||||
return this._windowFormConfigs;
|
||||
}
|
||||
}
|
||||
81
src/core/process/impl/ProcessManageImpl.ts
Normal file
81
src/core/process/impl/ProcessManageImpl.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import type ProcessImpl from './ProcessImpl.ts'
|
||||
import { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.ts'
|
||||
import { BasicSystemProcessInfo } from '@/core/system/BasicSystemProcessInfo.ts'
|
||||
import { DesktopProcessInfo } from '@/core/desktop/DesktopProcessInfo.ts'
|
||||
import type { IAppProcessInfoParams } from '@/core/process/types/IAppProcessInfoParams.ts'
|
||||
import type { IProcessManage } from '@/core/process/IProcessManage.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
|
||||
/**
|
||||
* 进程管理
|
||||
*/
|
||||
export default class ProcessManageImpl implements IProcessManage {
|
||||
private _processPool: Map<string, IProcess> = new Map<string, IProcess>();
|
||||
private _processInfos: IProcessInfo[] = new Array<ProcessInfoImpl>();
|
||||
|
||||
public get processInfos() {
|
||||
return this._processInfos;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
console.log('ProcessManageImpl')
|
||||
this.loadAppProcessInfos();
|
||||
}
|
||||
// TODO 加载所有进程信息
|
||||
private loadAppProcessInfos() {
|
||||
console.log('加载所有进程信息')
|
||||
// 添加内置进程
|
||||
const apps = import.meta.glob<IAppProcessInfoParams>('../../apps/**/*.json', { eager: true })
|
||||
const internalProcessInfos: ProcessInfoImpl[] = Object.values(apps).map(data => new ProcessInfoImpl(data))
|
||||
|
||||
this._processInfos.push(BasicSystemProcessInfo)
|
||||
this._processInfos.push(DesktopProcessInfo)
|
||||
|
||||
this._processInfos.push(...internalProcessInfos)
|
||||
}
|
||||
|
||||
// 添加进程
|
||||
public addProcess(process: ProcessImpl) {
|
||||
this._processPool.set(process.id, process);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过进程id查找进程
|
||||
* @param id 进程id
|
||||
*/
|
||||
public findProcessById(id: string) {
|
||||
return this._processPool.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过进程名称查找进程
|
||||
* @param name 进程名称
|
||||
*/
|
||||
public findProcessByName<T extends IProcess = IProcess>(name: string) {
|
||||
const pools = [...this._processPool.values()];
|
||||
return pools.find(proc => proc.processInfo.name === name) as T | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据进程id删除进程
|
||||
* @param id 进程id
|
||||
*/
|
||||
public removeProcess(id: string): void;
|
||||
/**
|
||||
* 根据进程删除进程
|
||||
* @param process 进程信息
|
||||
*/
|
||||
public removeProcess(process: IProcess): void;
|
||||
public removeProcess(params: string | IProcess) {
|
||||
const id = typeof params === 'string' ? params : params.id;
|
||||
this._processPool.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过进程名称查找进程信息
|
||||
*/
|
||||
public findProcessInfoByName(name: string) {
|
||||
return this._processInfos.find(info => info.name === name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user