79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import ProcessImpl from './process/impl/ProcessImpl.ts'
|
|
import { isUndefined } from 'lodash'
|
|
import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts'
|
|
import { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
|
import type { IProcess } from '@/core/process/IProcess.ts'
|
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
|
import { ObservableWeakRefImpl } from '@/core/state/impl/ObservableWeakRefImpl.ts'
|
|
import type { IObservable } from '@/core/state/IObservable.ts'
|
|
import { NotificationService } from '@/core/service/services/NotificationService.ts'
|
|
import { SettingsService } from '@/core/service/services/SettingsService.ts'
|
|
import { WindowFormService } from '@/core/service/services/WindowFormService.ts'
|
|
import { UserService } from '@/core/service/services/UserService.ts'
|
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
|
|
|
interface IGlobalState {
|
|
isLogin: boolean
|
|
}
|
|
|
|
export default class XSystem {
|
|
private static _instance: XSystem = new XSystem()
|
|
|
|
private _globalState: IObservable<IGlobalState> = new ObservableWeakRefImpl<IGlobalState>({
|
|
isLogin: false
|
|
})
|
|
private _desktopRootDom: HTMLElement;
|
|
|
|
constructor() {
|
|
console.log('XSystem')
|
|
new NotificationService()
|
|
new SettingsService()
|
|
new WindowFormService()
|
|
new UserService()
|
|
}
|
|
|
|
public static get instance() {
|
|
return this._instance
|
|
}
|
|
public get globalState() {
|
|
return this._globalState
|
|
}
|
|
public get desktopRootDom() {
|
|
return this._desktopRootDom
|
|
}
|
|
|
|
public initialization(dom: HTMLDivElement) {
|
|
this._desktopRootDom = dom
|
|
this.run('basic-system', BasicSystemProcess).then(() => {
|
|
this.run('desktop', DesktopProcess).then((proc) => {
|
|
proc.mount(dom)
|
|
// console.log(dom.querySelector('.desktop-root'))
|
|
})
|
|
})
|
|
}
|
|
|
|
// 运行进程
|
|
public async run<T extends IProcess = IProcess>(
|
|
proc: string | IProcessInfo,
|
|
constructor?: new (info: IProcessInfo) => T,
|
|
): Promise<T> {
|
|
let info = typeof proc === 'string' ? processManager.findProcessInfoByName(proc)! : proc
|
|
if (isUndefined(info)) {
|
|
throw new Error(`未找到进程信息:${proc}`)
|
|
}
|
|
|
|
// 是单例应用
|
|
if (info.singleton) {
|
|
let process = processManager.findProcessByName(info.name)
|
|
if (process) {
|
|
return process as T
|
|
}
|
|
}
|
|
|
|
// 创建进程
|
|
let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info)
|
|
|
|
return process as T
|
|
}
|
|
}
|