优化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type ProcessImpl from './ProcessImpl.ts'
|
||||
import 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'
|
||||
@@ -6,6 +6,8 @@ import type { IAppProcessInfoParams } from '@/core/process/types/IAppProcessInfo
|
||||
import type { IProcessManager } from '@/core/process/IProcessManager.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||
import { isUndefined } from 'lodash'
|
||||
|
||||
/**
|
||||
* 进程管理
|
||||
@@ -35,6 +37,29 @@ export default class ProcessManagerImpl implements IProcessManager {
|
||||
this._processInfos.push(...internalProcessInfos)
|
||||
}
|
||||
|
||||
public async runProcess<T extends IProcess = IProcess>(
|
||||
proc: string | IProcessInfo,
|
||||
constructor?: new (info: IProcessInfo) => T,
|
||||
): Promise<T> {
|
||||
let info = typeof proc === 'string' ? this.findProcessInfoByName(proc) : proc
|
||||
if (isUndefined(info)) {
|
||||
throw new Error(`未找到进程信息:${proc}`)
|
||||
}
|
||||
|
||||
// 是单例应用
|
||||
if (info.singleton) {
|
||||
let process = this.findProcessByName(info.name)
|
||||
if (process) {
|
||||
return process as T
|
||||
}
|
||||
}
|
||||
|
||||
// 创建进程
|
||||
let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info)
|
||||
|
||||
return process as T
|
||||
}
|
||||
|
||||
// 添加进程
|
||||
public registerProcess(process: ProcessImpl) {
|
||||
this._processPool.set(process.id, process);
|
||||
|
||||
Reference in New Issue
Block a user