初始化
This commit is contained in:
63
src/core/XSystem.ts
Normal file
63
src/core/XSystem.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import ProcessManages from './process/ProcessManages.ts'
|
||||
import AppProcess from './process/AppProcess.ts'
|
||||
import type { AppProcessInfo } from '@/core/process/AppProcessInfo.ts'
|
||||
import { isUndefined } from 'lodash'
|
||||
import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts'
|
||||
import { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
||||
import type { IAllEvent } from '@/core/events/EventTypes.ts'
|
||||
import type { IEventBuilder } from '@/core/events/IEventBuilder.ts'
|
||||
import { EventBuilderImpl } from '@/core/events/impl/EventBuilderImpl.ts'
|
||||
|
||||
export default class XSystem {
|
||||
private static _instance: XSystem = new XSystem()
|
||||
|
||||
private _processManages: ProcessManages = new ProcessManages()
|
||||
private _eventManages: IEventBuilder<IAllEvent> = new EventBuilderImpl()
|
||||
|
||||
constructor() {
|
||||
console.log('XSystem')
|
||||
}
|
||||
|
||||
public static get instance() {
|
||||
return this._instance
|
||||
}
|
||||
public get processManages() {
|
||||
return this._processManages
|
||||
}
|
||||
public get eventManages() {
|
||||
return this._eventManages
|
||||
}
|
||||
|
||||
public initialization(dom: HTMLDivElement) {
|
||||
this.run('basic-system', BasicSystemProcess).then(() => {
|
||||
this.run('desktop', DesktopProcess).then((proc) => {
|
||||
console.log(proc)
|
||||
proc.mount(dom)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 运行进程
|
||||
public async run<T extends AppProcess = AppProcess>(
|
||||
proc: string | AppProcessInfo,
|
||||
constructor?: new (info: AppProcessInfo) => T,
|
||||
): Promise<T> {
|
||||
let info = typeof proc === 'string' ? this._processManages.findProcessInfoByName(proc) : proc
|
||||
if (isUndefined(info)) {
|
||||
throw new Error(`未找到进程信息:${proc}`)
|
||||
}
|
||||
|
||||
// 是单例应用
|
||||
if (info.singleton) {
|
||||
let process = this._processManages.findProcessByName(info.name)
|
||||
if (process) {
|
||||
return process as T
|
||||
}
|
||||
}
|
||||
|
||||
// 创建进程
|
||||
let process = isUndefined(constructor) ? new AppProcess(info) : new constructor(info)
|
||||
|
||||
return process as T
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user