保存一下
This commit is contained in:
20
src/core/process/IProcess.ts
Normal file
20
src/core/process/IProcess.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.ts'
|
||||
import type WindowForm from '@/core/window/WindowForm.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
|
||||
/**
|
||||
* 进程接口
|
||||
*/
|
||||
export interface IProcess {
|
||||
/** 进程id */
|
||||
get id(): string;
|
||||
/** 进程信息 */
|
||||
get processInfo(): IProcessInfo;
|
||||
/** 进程的窗体列表 */
|
||||
get windowForms(): Map<string, WindowForm>;
|
||||
/**
|
||||
* 打开窗体
|
||||
* @param startName 窗体启动名
|
||||
*/
|
||||
openWindowForm(startName: string): void;
|
||||
}
|
||||
26
src/core/process/IProcessInfo.ts
Normal file
26
src/core/process/IProcessInfo.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { IVersion } from '@/core/common/types/IVersion.ts'
|
||||
import type { IWindowFormConfig } from '@/core/window/types/IWindowFormConfig.ts'
|
||||
|
||||
/**
|
||||
* 进程的描述信息
|
||||
*/
|
||||
export interface IProcessInfo {
|
||||
/** 进程名称 - 唯一 */
|
||||
get name(): string;
|
||||
/** 进程标题 */
|
||||
get title(): string;
|
||||
/** 进程描述 */
|
||||
get description(): string;
|
||||
/** 进程图标 */
|
||||
get icon(): string;
|
||||
/** 启动窗体名称 */
|
||||
get startName(): string;
|
||||
/** 进程版本 */
|
||||
get version(): IVersion;
|
||||
/** 是否单例进程 */
|
||||
get singleton(): boolean;
|
||||
/** 是否仅进程 */
|
||||
get isJustProcess(): boolean;
|
||||
/** 进程的窗体配置 */
|
||||
get windowFormConfigs(): IWindowFormConfig[];
|
||||
}
|
||||
41
src/core/process/IProcessManage.ts
Normal file
41
src/core/process/IProcessManage.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
|
||||
/**
|
||||
* 进程管理
|
||||
*/
|
||||
export interface IProcessManage {
|
||||
/** 所有进程信息 */
|
||||
get processInfos(): IProcessInfo[];
|
||||
/**
|
||||
* 添加进程
|
||||
* @param process 进程
|
||||
*/
|
||||
addProcess(process: IProcess): void;
|
||||
/**
|
||||
* 通过进程id查找进程
|
||||
* @param id 进程id
|
||||
*/
|
||||
findProcessById(id: string): IProcess | undefined;
|
||||
/**
|
||||
* 通过进程名查找进程
|
||||
* @param name 进程名
|
||||
*/
|
||||
findProcessByName<T extends IProcess = IProcess>(name: string): T | undefined;
|
||||
/**
|
||||
* 通过进程id删除进程
|
||||
* @param id 进程id
|
||||
*/
|
||||
removeProcess(id: string): void;
|
||||
/**
|
||||
* 通过进程对象删除进程
|
||||
* @param process 进程对象
|
||||
*/
|
||||
removeProcess(process: IProcess): void;
|
||||
/**
|
||||
* 通过进程名查找进程信息
|
||||
* @param name 进程名
|
||||
*/
|
||||
findProcessInfoByName(name: string): IProcessInfo | undefined;
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import XSystem from '../XSystem.ts'
|
||||
import type { AppProcessInfo } from '../process/AppProcessInfo.ts'
|
||||
import WindowForm from '../window/WindowForm.ts'
|
||||
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 AppProcess {
|
||||
export default class ProcessImpl implements IProcess {
|
||||
private readonly _id: string = uuidV4();
|
||||
private readonly _processInfo: AppProcessInfo;
|
||||
private readonly _processInfo: IProcessInfo;
|
||||
// 当前进程的窗体集合
|
||||
private _windowForms: Map<string, WindowForm> = new Map();
|
||||
|
||||
@@ -22,13 +23,13 @@ export default class AppProcess {
|
||||
return this._windowForms;
|
||||
}
|
||||
|
||||
constructor(info: AppProcessInfo) {
|
||||
constructor(info: IProcessInfo) {
|
||||
console.log(`AppProcess: ${info.name}`)
|
||||
this._processInfo = info;
|
||||
|
||||
const startName = info.startName;
|
||||
|
||||
XSystem.instance.processManages.addProcess(this);
|
||||
XSystem.instance.processManage.addProcess(this);
|
||||
// 通过设置 isJustProcess 为 true,则不会创建窗体
|
||||
if (!info.isJustProcess) {
|
||||
this.openWindowForm(startName)
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Version } from '../common/types/Version.ts'
|
||||
import type { IAppProcessInfoParams } from './types/IAppProcessInfoParams.ts'
|
||||
import type { WindowFormConfig } from '../window/types/WindowFormConfig.ts'
|
||||
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 AppProcessInfo {
|
||||
export class ProcessInfoImpl implements IProcessInfo {
|
||||
/**
|
||||
* 应用进程名称
|
||||
* @private
|
||||
@@ -38,7 +39,7 @@ export class AppProcessInfo {
|
||||
* 应用版本信息
|
||||
* @private
|
||||
*/
|
||||
private readonly _version: Version;
|
||||
private readonly _version: IVersion;
|
||||
|
||||
/**
|
||||
* 应用是否只存在一个进程
|
||||
@@ -56,7 +57,7 @@ export class AppProcessInfo {
|
||||
* 进程所有的窗口配置信息
|
||||
* @private
|
||||
*/
|
||||
private readonly _windowFormConfigs: Array<WindowFormConfig>;
|
||||
private readonly _windowFormConfigs: Array<IWindowFormConfig>;
|
||||
|
||||
constructor(info: IAppProcessInfoParams) {
|
||||
this._name = info.name;
|
||||
@@ -1,30 +1,33 @@
|
||||
import type AppProcess from './AppProcess.ts'
|
||||
import { AppProcessInfo } from '@/core/process/AppProcessInfo.ts'
|
||||
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 ProcessManages {
|
||||
private _processPool: Map<string, AppProcess> = new Map<string, AppProcess>();
|
||||
private _processInfos: AppProcessInfo[] = [];
|
||||
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('ProcessManages')
|
||||
console.log('ProcessManageImpl')
|
||||
this.loadAppProcessInfos();
|
||||
}
|
||||
// TODO 加载所有进程信息
|
||||
public loadAppProcessInfos() {
|
||||
private loadAppProcessInfos() {
|
||||
console.log('加载所有进程信息')
|
||||
// 添加内置进程
|
||||
const apps = import.meta.glob<IAppProcessInfoParams>('../apps/**/*.json', { eager: true })
|
||||
const internalProcessInfos: AppProcessInfo[] = Object.values(apps).map(data => new AppProcessInfo(data))
|
||||
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)
|
||||
@@ -33,7 +36,7 @@ export default class ProcessManages {
|
||||
}
|
||||
|
||||
// 添加进程
|
||||
public addProcess(process: AppProcess) {
|
||||
public addProcess(process: ProcessImpl) {
|
||||
this._processPool.set(process.id, process);
|
||||
}
|
||||
|
||||
@@ -49,9 +52,9 @@ export default class ProcessManages {
|
||||
* 通过进程名称查找进程
|
||||
* @param name 进程名称
|
||||
*/
|
||||
public findProcessByName<T extends AppProcess = AppProcess>(name: string) {
|
||||
public findProcessByName<T extends IProcess = IProcess>(name: string) {
|
||||
const pools = [...this._processPool.values()];
|
||||
return pools.find(proc => proc.processInfo.name === name) as T;
|
||||
return pools.find(proc => proc.processInfo.name === name) as T | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,8 +66,8 @@ export default class ProcessManages {
|
||||
* 根据进程删除进程
|
||||
* @param process 进程信息
|
||||
*/
|
||||
public removeProcess(process: AppProcess): void;
|
||||
public removeProcess(params: string | AppProcess) {
|
||||
public removeProcess(process: IProcess): void;
|
||||
public removeProcess(params: string | IProcess) {
|
||||
const id = typeof params === 'string' ? params : params.id;
|
||||
this._processPool.delete(id);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Version } from '../../common/types/Version.ts'
|
||||
import type { WindowFormConfig } from '../../window/types/WindowFormConfig.ts'
|
||||
import type { IVersion } from '../../common/types/IVersion.ts'
|
||||
import type { IWindowFormConfig } from '../../window/types/IWindowFormConfig.ts'
|
||||
|
||||
/**
|
||||
* 应用进程入参信息
|
||||
@@ -16,11 +16,11 @@ export interface IAppProcessInfoParams {
|
||||
/** 应用进程启动入口 */
|
||||
startName?: string;
|
||||
/** 应用版本信息 */
|
||||
version?: Version;
|
||||
version?: IVersion;
|
||||
/** 应用是否只存在一个进程 */
|
||||
singleton: boolean;
|
||||
/** 是否只是一个进程, 没有UI */
|
||||
isJustProcess: boolean;
|
||||
/** 进程所有的窗口配置信息 */
|
||||
windowFormConfigs?: WindowFormConfig[];
|
||||
windowFormConfigs?: IWindowFormConfig[];
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
* <p>onProcessWindowFormFocus - 进程的窗体获取焦点</p>
|
||||
*
|
||||
*/
|
||||
type AppProcessEvent =
|
||||
type TAppProcessEvent =
|
||||
'onProcessExit' |
|
||||
'onProcessWindowFormOpen' |
|
||||
'onProcessWindowFormExit' |
|
||||
Reference in New Issue
Block a user