fixed: 插件安装取消问题

Change-Id: Ic154cc646f0702d380c3f1b793ca260ec863de43
This commit is contained in:
dinglili 2024-08-08 09:57:14 +08:00 committed by wangpenglong
parent c7ecb9d7ad
commit f9b1e976d7
1 changed files with 12 additions and 5 deletions

View File

@ -221,12 +221,14 @@ export class DeployMainService implements IDeployMainService {
listenerInstallProcess = async (event: IpcMainEvent, msg: any) => {
if (msg.type === 'installExt') {
const logFile0 = this.installConfig + '/log/extInstall.1.log';
if (!fs.existsSync(logFile0)) {
fs.mkdirSync(this.installConfig + "/log", { recursive: true });
}
let installCommand = "";
if (this.cancelFlag) return;
try {
const installItem = this.extDownloadPath + msg.downloadDone;
if (this.environmentMainService.isBuilt) {
@ -245,7 +247,8 @@ export class DeployMainService implements IDeployMainService {
}
else {
this.installQueue?.push({ installCommand, msg });
if (!this.cancelFlag)
this.installQueue?.push({ installCommand, msg });
}
} catch (error) {
this.logger.error(`安装 ext 执行出错 ${installCommand}: ${error.message}`);
@ -1063,7 +1066,6 @@ export class DeployMainService implements IDeployMainService {
}
}
}
async executeNextInstall() {
if (this.installQueue?.length === 0) {
return; // 队列为空,结束执行
@ -1098,6 +1100,8 @@ export class DeployMainService implements IDeployMainService {
};
if (this.DeployWindow && !this.cancelFlag) {
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
} else {
this.installQueue.splice(0);
}
} catch (error) {
this.logger.error(`执行命令失败 ${installCommand}${error.message}`);
@ -1114,19 +1118,22 @@ export class DeployMainService implements IDeployMainService {
extTotal: this.extList.length,
extName: msg.extName
};
if (this.DeployWindow) {
if (this.DeployWindow && !this.cancelFlag) {
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
} else {
this.installQueue.splice(0);
}
}
this.installQueue.shift(); // 执行完成后,将当前消息从队列中移除
if (!this.cancelFlag)
await this.executeNextInstall(); // 继续执行下一个消息
else { this.installQueue.splice(0) }
}
spawnCommand(command: string) {
return new Promise((resolve, reject) => {
const child = spawn(command, { shell: true });
const child = spawn('sh', ['-c', command], { detached: true });
let stdout = '';
let stderr = '';
@ -1150,8 +1157,8 @@ export class DeployMainService implements IDeployMainService {
const cancelTask = () => {
if (child.pid)
execSync(`kill -9 -${child.pid}`);
this.controller.signal.addEventListener('abort', cancelTask);
}
this.controller.signal.addEventListener('abort', cancelTask);
});
}