初始化
This commit is contained in:
42
src/core/process/AppProcess.ts
Normal file
42
src/core/process/AppProcess.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import XSystem from '../XSystem.ts'
|
||||
import type { AppProcessInfo } from '../process/AppProcessInfo.ts'
|
||||
import WindowForm from '../window/WindowForm.ts'
|
||||
|
||||
/**
|
||||
* 进程
|
||||
*/
|
||||
export default class AppProcess {
|
||||
private readonly _id: string = uuidV4();
|
||||
private readonly _processInfo: AppProcessInfo;
|
||||
// 当前进程的窗体集合
|
||||
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: AppProcessInfo) {
|
||||
console.log(`AppProcess: ${info.name}`)
|
||||
this._processInfo = info;
|
||||
|
||||
const startName = info.startName;
|
||||
|
||||
XSystem.instance.processManages.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);
|
||||
}
|
||||
}
|
||||
100
src/core/process/AppProcessInfo.ts
Normal file
100
src/core/process/AppProcessInfo.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import type { Version } from '../common/types/Version.ts'
|
||||
import type { AppProcessInfoParams } from '../process/types/AppProcessInfoParams.ts'
|
||||
import type { WindowFormConfig } from '../window/types/WindowFormConfig.ts'
|
||||
|
||||
export class AppProcessInfo {
|
||||
/**
|
||||
* 应用进程名称
|
||||
* @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: Version;
|
||||
|
||||
/**
|
||||
* 应用是否只存在一个进程
|
||||
* @private
|
||||
*/
|
||||
private readonly _singleton: boolean;
|
||||
|
||||
/**
|
||||
* 是否只是一个进程
|
||||
* @private
|
||||
*/
|
||||
private readonly _isJustProcess: boolean;
|
||||
|
||||
/**
|
||||
* 进程所有的窗口配置信息
|
||||
* @private
|
||||
*/
|
||||
private readonly _windowFormConfigs: Array<WindowFormConfig>;
|
||||
|
||||
constructor(info: AppProcessInfoParams) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
78
src/core/process/ProcessManages.ts
Normal file
78
src/core/process/ProcessManages.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import type AppProcess from './AppProcess.ts'
|
||||
import { AppProcessInfo } from '@/core/process/AppProcessInfo.ts'
|
||||
import { BasicSystemProcessInfo } from '@/core/system/BasicSystemProcessInfo.ts'
|
||||
import { DesktopProcessInfo } from '@/core/desktop/DesktopProcessInfo.ts'
|
||||
import type { AppProcessInfoParams } from '@/core/process/types/AppProcessInfoParams.ts'
|
||||
|
||||
/**
|
||||
* 进程管理
|
||||
*/
|
||||
export default class ProcessManages {
|
||||
private _processPool: Map<string, AppProcess> = new Map<string, AppProcess>();
|
||||
private _processInfos: AppProcessInfo[] = [];
|
||||
|
||||
public get processInfos() {
|
||||
return this._processInfos;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
console.log('ProcessManages')
|
||||
this.loadAppProcessInfos();
|
||||
}
|
||||
// TODO 加载所有进程信息
|
||||
public loadAppProcessInfos() {
|
||||
console.log('加载所有进程信息')
|
||||
// 添加内置进程
|
||||
const apps = import.meta.glob<AppProcessInfoParams>('../apps/**/*.json', { eager: true })
|
||||
const internalProcessInfos: AppProcessInfo[] = Object.values(apps).map(data => new AppProcessInfo(data))
|
||||
|
||||
this._processInfos.push(BasicSystemProcessInfo)
|
||||
this._processInfos.push(DesktopProcessInfo)
|
||||
|
||||
this._processInfos.push(...internalProcessInfos)
|
||||
}
|
||||
|
||||
// 添加进程
|
||||
public addProcess(process: AppProcess) {
|
||||
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 AppProcess = AppProcess>(name: string) {
|
||||
const pools = [...this._processPool.values()];
|
||||
return pools.find(proc => proc.processInfo.name === name) as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据进程id删除进程
|
||||
* @param id 进程id
|
||||
*/
|
||||
public removeProcess(id: string): void;
|
||||
/**
|
||||
* 根据进程删除进程
|
||||
* @param process 进程信息
|
||||
*/
|
||||
public removeProcess(process: AppProcess): void;
|
||||
public removeProcess(params: string | AppProcess) {
|
||||
const id = typeof params === 'string' ? params : params.id;
|
||||
this._processPool.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过进程名称查找进程信息
|
||||
*/
|
||||
public findProcessInfoByName(name: string) {
|
||||
return this._processInfos.find(info => info.name === name);
|
||||
}
|
||||
}
|
||||
14
src/core/process/types/AppProcessEvent.ts
Normal file
14
src/core/process/types/AppProcessEvent.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 进程的事件
|
||||
* <p>onProcessExit - 进程退出</p>
|
||||
* <p>onProcessWindowFormOpen - 进程的窗体打开</p>
|
||||
* <p>onProcessWindowFormExit - 进程的窗体退出</p>
|
||||
* <p>onProcessWindowFormFocus - 进程的窗体获取焦点</p>
|
||||
*
|
||||
*/
|
||||
type AppProcessEvent =
|
||||
'onProcessExit' |
|
||||
'onProcessWindowFormOpen' |
|
||||
'onProcessWindowFormExit' |
|
||||
'onProcessWindowFormFocus' |
|
||||
'onProcessWindowFormBlur'
|
||||
26
src/core/process/types/AppProcessInfoParams.ts
Normal file
26
src/core/process/types/AppProcessInfoParams.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { Version } from '../../common/types/Version.ts'
|
||||
import type { WindowFormConfig } from '../../window/types/WindowFormConfig.ts'
|
||||
|
||||
/**
|
||||
* 应用进程入参信息
|
||||
*/
|
||||
export interface AppProcessInfoParams {
|
||||
/** 应用进程名称 */
|
||||
name: string;
|
||||
/** 应用进程标题 */
|
||||
title?: string;
|
||||
/** 应用进程描述 */
|
||||
description?: string;
|
||||
/** 应用进程图标 */
|
||||
icon?: string;
|
||||
/** 应用进程启动入口 */
|
||||
startName?: string;
|
||||
/** 应用版本信息 */
|
||||
version?: Version;
|
||||
/** 应用是否只存在一个进程 */
|
||||
singleton: boolean;
|
||||
/** 是否只是一个进程, 没有UI */
|
||||
isJustProcess: boolean;
|
||||
/** 进程所有的窗口配置信息 */
|
||||
windowFormConfigs?: WindowFormConfig[];
|
||||
}
|
||||
Reference in New Issue
Block a user