解决安装显示失败问题

This commit is contained in:
dinglili 2024-05-30 16:43:12 +08:00 committed by wangpenglong
parent e15ef0b7ba
commit 3056055f44
3 changed files with 283 additions and 31 deletions

View File

@ -1481,7 +1481,7 @@ export class CodeApplication extends Disposable {
}
private async isFirstLoad(): Promise<boolean> {
let res = false;
const userDataPath = path.join(this.environmentMainService.userHome.fsPath, '.config', 'Kylin-IDE', 'installconfig');
const userDataPath = path.join(this.environmentMainService.userHome.fsPath, '.config', 'Kylin-Code', 'installconfig');
const flagFilePath = path.join(userDataPath, 'first-run.flag');
if (!fs.existsSync(userDataPath)) {

View File

@ -239,8 +239,8 @@ class deployWindow {
preElement!.innerHTML = "";
const messageData = {
url: utils.get_g_index_url(),
dst: utils.configDir()
// url: utils.get_g_index_url(),
// dst: utils.configDir()
}
//联网检查是否有合适的文件
ipcRenderer.send("kylinide.installWizard.checkInstall", messageData);
@ -575,19 +575,6 @@ class deployWindow {
}
console.log("extInstallState.size" + this.extInstallState.size);
// if (selectedCheckboxes) {
// // 遍历选中的复选框,并将它们的值添加到数组中
// selectedCheckboxes.forEach(function (checkbox) {
// if (checkbox.value != "JavaScript_key")
// checkSelectedValues.push(checkbox.value);
// });
// logger.info("config:checkbox choice:" + checkSelectedValues);
// }
// document.getElementsByClassName("download-view")[0].value = 0;
// document.getElementsByClassName("progress-download")[0].innerHTML = "插件下载进度:0%";
// document.getElementsByClassName("install-view")[0].value = 0;
// document.getElementsByClassName("progress-install")[0].innerHTML = "插件安装进度:0%";
let progress_view = document.getElementsByClassName("progress-view") as HTMLCollectionOf<HTMLProgressElement>;
progress_view[0].value = 0;
document.getElementsByClassName("progressinfo")[0].innerHTML = "安装进度:0%";
@ -995,9 +982,9 @@ class deployWindow {
}
//页面更新
let extList = [];
let depList = [];
let scriptList = [];
this.extList = [];
this.depList = [];
this.scriptList = [];
if (Object.keys(configList).length > 0) {
this.nextBtn!.disabled = false;
} else {
@ -1006,14 +993,14 @@ class deployWindow {
for (let key in configList) {
for (let val of configList[key]["ext-list"]) {
extList.push(val);
this.extList.push(val);
}
}
extList = [...new Set(extList)];
this.extList = [...new Set(this.extList)];
for (let key in configList) {
for (let val of configList[key]["script-list"]) {
scriptList.push(val);
this.scriptList.push(val);
}
}
@ -1032,31 +1019,31 @@ class deployWindow {
// }
if (tDepList["deb"]) {
for (let key in tDepList["deb"]) {
depList.push(key);
this.depList.push(key);
}
}
}
depList = [...new Set(depList)];
this.depList = [...new Set(this.depList)];
var SelectedDatas = {
configList: configList,
extList: extList,
depList: depList,
scriptList: scriptList
extList: this.extList,
depList: this.depList,
scriptList: this.scriptList
}
ipcRenderer.send('message-to-jsb', SelectedDatas);
if (depList.length > 0) {
ipcRenderer.send('kylinide.installWizard.msg.deplist', SelectedDatas);
if (this.depList.length > 0) {
formattedDoc = '<h2>软件列表:<span style="color: yellow; font-size: 12px;">请点击下一步输入密码安装以下软件</span></h2>';
}
else
formattedDoc = '<h2>软件列表:</h2>';
formattedDoc += Object.values(depList).map(element => `<h4 style='font-size: 16px; line-height: 0.1;margin-left:20px;'>${element}</h4>`).join('');
formattedDoc += Object.values(this.depList).map(element => `<h4 style='font-size: 16px; line-height: 0.1;margin-left:20px;'>${element}</h4>`).join('');
formattedDoc += '<h2>插件列表:</h2>';
formattedDoc += extList.map(element => `<h4 style='font-size: 16px; line-height: 0.1;margin-left:20px;'>${element}</h4>`).join('');
formattedDoc += this.extList.map(element => `<h4 style='font-size: 16px; line-height: 0.1;margin-left:20px;'>${element}</h4>`).join('');
document.getElementById("outputPre")!.innerHTML = formattedDoc;
});

View File

@ -116,6 +116,8 @@ export class DeployMainService implements IDeployMainService {
//执行安装脚本的进程号;
installProcessId: ChildProcess | null = null;
cancelFlag = false;
offset = 0;
resultIndex = 0;
flagPkexec = 0;
maxBackupFiles = 7;
@ -126,6 +128,13 @@ export class DeployMainService implements IDeployMainService {
extLogFile0 = "";
controller = new AbortController();
DownSelectKey: any = {
depArry: [],
goInfoArry: [],
pip3InfoArry: []
};
startInstallDepWatch = 0;
constructor(
private userEnv: IProcessEnvironment,
@ -372,6 +381,17 @@ export class DeployMainService implements IDeployMainService {
}
});
validatedIpcMain.on('kylinide.installWizard.msg.deplist', (event, message) => {
this.depList = [];
this.extList = [];
// scriptList = [];
this.depList = message.depList;
this.extList = message.extList;
this.DownSelectKey.configList = message.configList;
// scriptList = message.scriptList;
this.extMap = {};
});
// validatedIpcMain.on('kylinide.installWizard.skipWizard', event => {
// logger.info("跳过操作");
// })
@ -784,6 +804,251 @@ export class DeployMainService implements IDeployMainService {
installUtils.modifyJsonProperty(this.installConfig + "/" + "selectFile.json", "selectKey", msg.keys);
}
});
validatedIpcMain.on('kylinide.installWizard.checkInstall', async (event, args) => {
console.log("kylinide.installWizard.checkInstall");
if (this.startInstallDepWatch === 1) return;
this.lastLogPosition = 0;
this.lastExtLogPosition = 0;
if (!fs.existsSync(this.logFile0)) {
fs.mkdirSync(this.installConfig, { recursive: true });
fs.writeFileSync(this.logFile0, '');
}
//监听install pkg输出信息
this.pkglogFsWatcher =
fs.watch(this.logFile0, (eventType, filename) => {
if (eventType === 'change') {
// 获取文件的当前大小
const stats = fs.statSync(this.logFile0);
const currentSize = stats.size;
if (this.lastLogPosition === 0 && stats.size > 0) {
const startDownloadExtMsg = {
type: "extDownloadInit",
}
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", startDownloadExtMsg)
const extlogFile0 = this.installConfig + '/log/extInstall.1.log';
fs.writeFileSync(extlogFile0, '');
}
// 计算更新部分的大小
const updateSize = currentSize - this.lastLogPosition;
if (updateSize <= 0) return;
// 读取更新部分的内容
const buffer = Buffer.alloc(updateSize);
const fileDescriptor = fs.openSync(this.logFile0, 'r');
fs.readSync(fileDescriptor, buffer, 0, updateSize, this.lastLogPosition);
fs.closeSync(fileDescriptor);
// 将更新部分的内容转换为字符串并输出
const updatedContent = buffer.toString('utf8');
// 更新上一次读取的位置
this.lastLogPosition = currentSize;
const installMsg = {
type: "installLogPre",
data: updatedContent
};
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
}
});
//检测ext 安装信息文件变化
this.extlogFsWatcher =
fs.watch(this.extLogFile0, (eventType, filename) => {
if (eventType === 'change') {
// 获取文件的当前大小
const stats = fs.statSync(this.extLogFile0);
const currentSize = stats.size;
// 计算更新部分的大小
const updateSize = currentSize - this.lastExtLogPosition;
if (updateSize <= 0) return;
// 读取更新部分的内容
const buffer = Buffer.alloc(updateSize);
const fileDescriptor = fs.openSync(this.extLogFile0, 'r');
fs.readSync(fileDescriptor, buffer, 0, updateSize, this.lastExtLogPosition);
fs.closeSync(fileDescriptor);
// 将更新部分的内容转换为字符串并输出
const updatedContent = buffer.toString('utf8');
// 更新上一次读取的位置
this.lastExtLogPosition = currentSize;
const installMsg = {
type: "extInstallLogPre",
data: updatedContent
};
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
}
});
this.installFsWatcher = fs.watch(this.resultFile, (evenType, filename) => {
if (evenType === "change") {
fs.readFile(this.resultFile, "utf8", (err, data) => {
if (err) {
console.error(`读取 resultFile 文件时发生错误:${err}`);
return;
}
// 计算文件变化的部分的偏移量
const newOffset = data.length;
// 如果文件没有发生变化,直接返回
if (newOffset === this.offset) {
return;
}
// 读取文件变化的部分
const changeData = data.slice(this.offset);
// 更新文件偏移量
this.offset = newOffset;
let result = changeData.trim();
// 处理文件变化的部分
console.log(`result ${this.resultIndex + 1} 结果为 ${result}`);
//每个dep的安装状态
let installMsg;
if (result === '') {
//此处是因为每次清零的时候会监听到改变
console.log(`result ${this.resultIndex + 1} 结果为空。`);
this.resultIndex = 0;
return;
} else if (result === '0') {
installMsg = {
type: "depInstallSucc",
depName: this.depList[this.resultIndex],
result: "0",
succ: this.resultIndex
};
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
} else {
installMsg = {
type: "depInstallFail",
depName: this.depList[this.resultIndex],
result: "0",
succ: this.resultIndex //失败
};
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
}
if (this.resultIndex == this.depList.length - 1) {
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.removeFileLister", { type: "installFile" });
this.resultIndex = 0;
return;
}
this.resultIndex++;
});
}
});
this.startInstallDepWatch = 1;
});
ipcMain.on('kylinide.installWizard.downloadExt', async (event, message) => {
this.installQueue.splice(0);
let depObject = JSON.parse(fs.readFileSync(message.extAddressPath, 'utf-8'));
let extLatestDownloadUrlList = [];
let extDownloadUrlList = [];
this.extDownloadPath = this.installConfig + '/Download/'
this.extList.forEach(async (val) => {
// await semaphore.acquire(); // 获取信号量,控制并发数量
let gitInfo = depObject[val]['ext_links']['gitee'];
let tempUrl = gitInfo.prefix + '/' + gitInfo.org + '/' + gitInfo.repo + '/' + 'releases/latest';
extLatestDownloadUrlList.push(tempUrl);
// download extension
try {
const response = await axios.get(tempUrl, {
headers: {
'User-Agent': 'axios',
'Accept': '*/*',
},
timeout: 10000,
signal: this.controller.signal
});
const downloadUrl = response.data.release.release.attach_files[0].download_url;
const downloadUrlAddr = gitInfo.prefix + downloadUrl;
extDownloadUrlList.push(downloadUrlAddr);
const start = downloadUrlAddr.lastIndexOf('/') + 1;
const filename = downloadUrlAddr.slice(start);
this.extMap[val] = filename;
const startDownloadMsg = {
type: 'extStartDownload',
extName: val,
extMap: this.extMap,
// extTotal: extMap.length,
extTotal: this.extList.length,
};
if (this.DeployWindow) this.DeployWindow.webContents.send('kylinide.installWizard.msg', startDownloadMsg);
if (!this.cancelFlag) {
this.download_File(downloadUrlAddr, this.extDownloadPath + filename, this.controller).then((result) => {
const msg = {
type: 'downloadExtDone',
fileName: filename,
extName: val,
extMap: this.extMap,
extTotal: Object.keys(this.extMap).length,
};
if (result === 0) {
if (this.DeployWindow) this.DeployWindow.webContents.send('kylinide.installWizard.msg', msg);
} else {
console.log(`Download ${val} failed0: `);
const msg = {
type: 'downloadExtFail',
fileName: filename,
extName: val,
extMap: this.extMap,
extTotal: Object.keys(this.extMap).length,
};
if (this.DeployWindow) this.DeployWindow.webContents.send('kylinide.installWizard.msg', msg);
}
}).catch((error) => {
console.log(`Download ${val} failed1: ${error}`);
const msg = {
type: 'downloadExtFail',
fileName: filename ? filename : val,
extName: val,
extMap: this.extMap,
// extTotal: Object.keys(extMap).length,
extTotal: this.extList.length,
};
if (this.DeployWindow) this.DeployWindow.webContents.send('kylinide.installWizard.msg', msg);
});
}
} catch (error) {
console.log(`Download ${val} failed2: ${error}`);
const msg = {
type: 'downloadExtFail',
fileName: val,
extName: val,
extMap: this.extMap,
// extTotal: Object.keys(extMap).length,
extTotal: this.extList.length,
};
if (this.DeployWindow) this.DeployWindow.webContents.send('kylinide.installWizard.msg', msg);
} finally {
// semaphore.release(); // 释放信号量
}
});
});
}