解决开发环境快速部署点击取消,不输入密码,安装进度到不了100%

This commit is contained in:
dinglili 2024-07-18 14:38:55 +08:00 committed by wangpenglong
parent 3a10c9abfd
commit c8629845bd
3 changed files with 58 additions and 36 deletions

View File

@ -1,6 +1,5 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<html>
<head>
<meta charset="utf-8" />
@ -155,15 +154,15 @@
<div class="detailInstallOutputTextbox">
<label for="detailInstallOutputTextbox">安装详情</label>
<button class="switchInstallOutput" id="switchInstallOutput">
<img src="./media/switch.png" style="display: inline-block;" alt="切换" width="10px" height="8px"/>
<div style="display: inline; margin-left: 4px; margin-right: 0px; padding: 0px;">切换输出</div>
</button>
<div>
<pre id="detailInstallPre" style="display: block"></pre>
<pre id="installLogPre" style="display: none"></pre>
<pre id="extInstallLogPre" style="display: none"></pre>
<pre id="finishPage" style="display: none"></pre>
<button class="switchInstallOutput" id="switchInstallOutput">
<img src="./media/switch.png" style="display: inline-block;" alt="切换" width="10px" height="8px"/>
<div style="display: inline-block; margin-left: 4px;">切换输出</div>
</button>
</div>
</div>
</div>

View File

@ -114,7 +114,7 @@ class deployWindow {
// dst: utils.configDir()
}
//联网检查是否有合适的文件
ipcRenderer.send("kylinide.installWizard.checkInstall", messageData);
await ipcRenderer.invoke('kylinide.installWizard.checkInstall', messageData);
}
else {
this.extInstallState.set(msg.depName, 11);
@ -473,7 +473,6 @@ class deployWindow {
type: "configSelect",
select: select
}
// ipcRenderer.send('kylinide.installWizard.init', data);
console.log("renderer send kylinide.installWizard.init.configSelect");
let result = await ipcRenderer.invoke('kylinide.installWizard.init.configSelect', data);
@ -1037,7 +1036,7 @@ class deployWindow {
});
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener("change", (event) => {
elements[i].addEventListener("change", async (event) => {
// 根据选中不同的checkbox显示不同输出
const target = event.target as HTMLInputElement;
if (target!.checked) {

View File

@ -82,7 +82,7 @@ export class DeployMainService implements IDeployMainService {
extDownloadPath: string = "";
// public extensionsGalleryConfiguration!: IExtensionsGalleryConfiguration;
// private preExtensionsGalleryConfig: IExtensionsGalleryConfiguration;
installQueue: { installCommand: any; msg: any; }[] = []; // 定义一个消息队列
installQueue: { installCommand: any; msg: any; }[] | null = []; // 定义一个消息队列
extMap: Record<string, string> = {};
depList: string[] = [];
extList: string[] = [];
@ -93,6 +93,7 @@ export class DeployMainService implements IDeployMainService {
pkglogFsWatcher: fs.FSWatcher | null = null;
//执行安装脚本的进程号;
installProcessId: ChildProcess | null = null;
cancelInstallProcessId: ChildProcess | null = null;
cancelFlag = false;
offset = 0;
resultIndex = 0;
@ -129,8 +130,8 @@ export class DeployMainService implements IDeployMainService {
this.updateConfigDir = installUtils.installConfigDirPre() + "/" + installUtils.getDateDir();
this.reset();
this.logger = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/instguide.log"));
this.loggerExt = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/extinstdetail.log"));
this.loggerSoft = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/softinstdetail.log"));
this.loggerExt = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/extdetail.log"));
this.loggerSoft = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/softdetail.log"));
this.removeListeners();
this.registerListeners();
}
@ -144,6 +145,7 @@ export class DeployMainService implements IDeployMainService {
this.logFile0 = this.installConfig + '/log/install.1.log';
this.resultFile = this.installConfig + '/resultFile';
this.extLogFile0 = this.installConfig + '/log/extInstall.1.log';
this.installQueue = [];
this.baseUrl = "";
this.extDownloadPath = "";
@ -157,6 +159,7 @@ export class DeployMainService implements IDeployMainService {
this.pkglogFsWatcher = null;
//执行安装脚本的进程号;
this.installProcessId = null;
this.cancelInstallProcessId = null;
this.cancelFlag = false;
this.offset = 0;
this.resultIndex = 0;
@ -222,12 +225,12 @@ export class DeployMainService implements IDeployMainService {
installCommand = comandpath + " " + "--install-extension" + " " + installItem;
}
this.logger.debug("安装 ext installCommand", installCommand);
if (this.installQueue.length === 0) {
if (this.installQueue?.length === 0) {
this.installQueue.push({ installCommand, msg });
await this.executeNextInstall();
}
else {
this.installQueue.push({ installCommand, msg });
this.installQueue?.push({ installCommand, msg });
}
} catch (error) {
this.logger.error(`安装 ext 执行出错 ${installCommand}: ${error.message}`);
@ -374,45 +377,45 @@ export class DeployMainService implements IDeployMainService {
this.logger.info("取消依赖包安装");
// var killcommand = `pkexec sudo pkill -TERM -P ${installProcessId.pid}`;
var killcommand = `pkexec sudo pkill -f 'bash ${this.installConfig}/install.sh'`;
const sudokill = spawn(killcommand, { shell: true, stdio: 'inherit' });
this.cancelInstallProcessId = spawn(killcommand, { shell: true, stdio: 'inherit' });
sudokill.on('exit', (code, signal) => {
this.cancelInstallProcessId.on('exit', (code, signal) => {
this.logger.info('取消安装结束', code)
if (code == 127) {
this.println('授权失败', code);
this.logger.error("取消安装授权失败");
if (code == 127 || code == 126) {
this.logger.error("取消安装授权失败:", code);
} else {
this.cancelFlag = true;
if (this.DeployWindow) {
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'installFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'extFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'pkgFile' });
}
this.controller.abort();
this.installQueue.splice(0);
this.installQueue?.splice(0);
this.installQueue = null;
//结束插件下载及安装
if (this.DeployWindow) {
this.DeployWindow.webContents.send("kylinide.installWizard.cancelInstall", { type: "cancelinstall" });
this.DeployWindow.webContents.send("kylinide.installWizard.msg", { type: "cancelinstall" });
}
}
this.println('kill Exit code:', code);
this.logger.info('kill Exit code:cancelinstallprocessid:', code);
});
this.println("取消安装after");
} else {
this.println("取消安装其他情况");
if (this.DeployWindow) {
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'installFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'extFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'pkgFile' });
}
this.logger.info("取消安装");
this.controller.abort();
this.cancelFlag = true;
this.installQueue.splice(0);
this.installQueue?.splice(0);
//结束插件下载及安装
if (this.DeployWindow) {
this.DeployWindow.webContents.send("kylinide.installWizard.cancelInstall", { type: 'cancelinstall' });
this.DeployWindow.webContents.send("kylinide.installWizard.msg", { type: "cancelinstall" });
}
if (this.DeployWindow) {
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'installFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'extFile' });
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: 'pkgFile' });
}
}
}
@ -664,8 +667,10 @@ export class DeployMainService implements IDeployMainService {
this.DownSelectKey.configList = msg.configList;
// scriptList = message.scriptList;
this.extMap = {};
return void 0;
};
listenerCheckInstall = async (event: IpcMainEvent, msg: any) => {
handleCheckInstall = async (event: IpcMainInvokeEvent, msg: any) => {
this.println("kylinide.installWizard.checkInstall");
if (this.startInstallDepWatch === 1) {
@ -718,7 +723,7 @@ export class DeployMainService implements IDeployMainService {
// this.logger.debug(`install pkg输出信息更新${updatedContent}`);
if (updatedContent.length > 0)
fs.appendFileSync(this.installConfig + "/log/soft.log", updatedContent);
fs.appendFileSync(this.installConfig + "/log/softdetail.log", updatedContent);
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
}
@ -826,12 +831,13 @@ export class DeployMainService implements IDeployMainService {
}
});
this.startInstallDepWatch = 1;
return void 0;
};
}
handleDownExten = async (event: IpcMainInvokeEvent, message: any) => {
listenerDownExten = async (event: IpcMainEvent, message: any) => {
this.installQueue.splice(0);
this.println("kylinide.installWizard.downloadExt");
this.installQueue?.splice(0);
let depObject = JSON.parse(fs.readFileSync(message.extAddressPath, 'utf-8'));
let extLatestDownloadUrlList = [];
let extDownloadUrlList = [];
@ -946,6 +952,7 @@ export class DeployMainService implements IDeployMainService {
private removeListeners(): void {
this.logger.info("移除监听器");
//接收从渲染进程发送的消息
validatedIpcMain.removeListener('kylinide.installWizard.show', this.listenerShow);
validatedIpcMain.removeListener('kylinide.installWizard.helpLink', this.listenerHelpLink);
validatedIpcMain.removeListener('kylinide.installWizard.minw', this.listenerMiniWindow);
validatedIpcMain.removeListener('kylinide.installWizard.closeWizard', this.listenerCloseWindow);
@ -956,6 +963,7 @@ export class DeployMainService implements IDeployMainService {
private registerListeners(): void {
this.logger.info("注册监听器");
//接收从渲染进程发送的消息
validatedIpcMain.on('kylinide.installWizard.show', this.listenerShow);
validatedIpcMain.on('kylinide.installWizard.helpLink', this.listenerHelpLink);
validatedIpcMain.on('kylinide.installWizard.minw', this.listenerMiniWindow);
validatedIpcMain.on('kylinide.installWizard.closeWizard', this.listenerCloseWindow);
@ -966,6 +974,12 @@ export class DeployMainService implements IDeployMainService {
//handle从渲染进程发送的消息
validatedIpcMain.handle('kylinide.installWizard.init.configVersify', this.handleInitConfigVersify);
validatedIpcMain.handle('kylinide.installWizard.init.configSelect', this.handleInitConfigSelect);
validatedIpcMain.handle('kylinide.installWizard.init.configGetValue', this.handleInitConfigGetValue);
validatedIpcMain.handle('kylinide.installWizard.init.httpVerify', this.handleHttpVerify);
validatedIpcMain.handle('kylinide.installWizard.msg.deplist', this.handleDepList);
validatedIpcMain.handle('kylinide.installWizard.checkInstall', this.handleCheckInstall);
validatedIpcMain.handle('kylinide.installWizard.downloadExt', this.handleDownExten);
}
//#endregion
@ -990,6 +1004,7 @@ export class DeployMainService implements IDeployMainService {
}
}
});
} catch (error) {
this.logger.error(`执行脚本时出错: ${error.message}`);
this.loggerSoft.error(`执行脚本时出错: ${error.message}`);
@ -1025,13 +1040,16 @@ export class DeployMainService implements IDeployMainService {
}
async executeNextInstall() {
if (this.installQueue.length === 0) {
if (this.installQueue?.length === 0) {
return; // 队列为空,结束执行
}
if (this.cancelFlag) {
this.installQueue.splice(0);
this.installQueue?.splice(0);
return;
}
if (!this.installQueue)
return;
const { installCommand, msg } = this.installQueue[0];
try {
const extlogFile = this.installConfig + '/log/extInstall.1.log';
@ -1128,6 +1146,12 @@ export class DeployMainService implements IDeployMainService {
closeWindow() {
if (this.DeployWindow) {
if (this.installProcessId) {
this.installProcessId.kill();
}
if (this.cancelInstallProcessId) {
this.cancelInstallProcessId.kill();
}
this.DeployWindow.close();
}
}