删除监听事件
This commit is contained in:
parent
9e714c643f
commit
2a2a520b14
|
@ -183,6 +183,14 @@
|
|||
|
||||
ipcRenderer.removeListener(channel, listener);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
removeAllListeners(channel) {
|
||||
validateIPC(channel);
|
||||
|
||||
ipcRenderer.removeAllListeners(channel);
|
||||
|
||||
return this;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -112,6 +112,7 @@ export interface IpcRenderer {
|
|||
// */
|
||||
// postMessage(channel: string, message: any, transfer?: MessagePort[]): void;
|
||||
removeListener(channel: string, listener: (...args: any[]) => void): this;
|
||||
removeAllListeners(channel: string): this;
|
||||
/**
|
||||
* Send an asynchronous message to the main process via `channel`, along with
|
||||
* arguments. Arguments will be serialized with the Structured Clone Algorithm,
|
||||
|
|
|
@ -128,8 +128,6 @@
|
|||
</div>
|
||||
<div class="devContent">
|
||||
<form id="checkboxForm">
|
||||
<script src="common.js"></script>
|
||||
<!-- 复选框列表 -->
|
||||
</form>
|
||||
|
||||
<div class="formSeparator"></div>
|
||||
|
@ -143,20 +141,6 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="tab" id="onlineInstallTab4">
|
||||
<div class="progress-container" style="display: none">
|
||||
<progress class="download-view" value="60" max="100"> </progress>
|
||||
<span class="progress-download">插件下载进度:60%</span>
|
||||
</div>
|
||||
|
||||
<div class="progress-container" style="display: none">
|
||||
<progress class="install-view" value="50" max="100"></progress>
|
||||
<span class="progress-install">插件安装进度:50%</span>
|
||||
</div>
|
||||
|
||||
<div class="progress-container" style="display: none">
|
||||
<progress class="pkg-install-view" value="50" max="100" style="overflow:hidden;"></progress>
|
||||
<span class="pkg-progress-install"></span>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<progress class="progress-view" value="50" max="100" style="overflow:hidden;"></progress>
|
||||
<span class="progressinfo"></span>
|
||||
|
|
|
@ -28,8 +28,6 @@ import { KeyCode } from 'vs/base/common/keyCodes';
|
|||
import { mainWindow } from 'vs/base/browser/window';
|
||||
import { ThemeIcon } from 'vs/base/common/themables';
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import * as utils from 'vs/platform/issue/electron-main/utils';
|
||||
|
||||
import { addDisposableListener, EventType, getWindow, getWindowId, hide, show } from 'vs/base/browser/dom';
|
||||
import { isDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
|
@ -124,7 +122,6 @@ class deployWindow {
|
|||
this.nextPrev(1);
|
||||
} else if (msg.type === "osinfo") {
|
||||
console.log("ipcRenderer osinfo ");
|
||||
// this.readOSInfo(msg);
|
||||
const parentdiv = document.getElementById('osInfo') as HTMLDivElement;
|
||||
const parentdivshow = document.getElementById('osInfoShow') as HTMLDivElement;
|
||||
parentdiv.innerHTML = "";
|
||||
|
@ -185,16 +182,6 @@ class deployWindow {
|
|||
}
|
||||
else if (msg.type == "downloadExtDone") {
|
||||
this.extDownloadDoneCounter++;
|
||||
let num = msg.extTotal;
|
||||
|
||||
let downloadViews = document.getElementsByClassName("download-view") as HTMLCollectionOf<HTMLProgressElement>;
|
||||
var val = downloadViews[0].value
|
||||
val = (this.extDownloadDoneCounter / num) * 100;
|
||||
val = parseInt(val.toFixed(2));
|
||||
console.log(msg.extName + "下载完成" + msg.fileName + ":" + num);
|
||||
if (val > 99) val = 100;
|
||||
downloadViews[0].value = val;
|
||||
document.getElementsByClassName("progress-download")[0].innerHTML = "插件下载进度:" + val + "%";
|
||||
const installMsg = {
|
||||
type: "installExt",
|
||||
extList: this.extList,
|
||||
|
@ -207,21 +194,9 @@ class deployWindow {
|
|||
}
|
||||
else if (msg.type == "extInstalled") {
|
||||
this.progressNum++;
|
||||
|
||||
const extName = this.getKeyByValue(msg.extFileName, this.extMap);
|
||||
this.extInstallDoneCounter++;
|
||||
let num = msg.extTotal;
|
||||
|
||||
let installViews = document.getElementsByClassName("install-view") as HTMLCollectionOf<HTMLProgressElement>;
|
||||
var val = installViews[0].value;
|
||||
val = (this.extInstallDoneCounter / num) * 100;
|
||||
val = parseInt(val.toFixed(2));
|
||||
if (val > 99) val = 100;
|
||||
console.log("extInstalled: " + extName + ":" + val);
|
||||
|
||||
this.extInstallState.set(extName, 12);
|
||||
installViews[0].value = val;
|
||||
document.getElementsByClassName("progress-install")[0].innerHTML = "插件安装进度:" + val + "%";
|
||||
}
|
||||
else if (msg.type == "extInstalledFail") {
|
||||
this.progressNum++;
|
||||
|
@ -250,23 +225,9 @@ class deployWindow {
|
|||
}
|
||||
}
|
||||
else if (msg.type == "depInstallSucc") {
|
||||
console.log("------dll---depInstallSucc");
|
||||
this.progressNum++;
|
||||
let num = this.depList.length;
|
||||
|
||||
let pkgInstallViews = document.getElementsByClassName("pkg-install-view") as HTMLCollectionOf<HTMLProgressElement>;
|
||||
var val = pkgInstallViews[0].value;
|
||||
pkgInstallViews[0].value = 0;
|
||||
document.getElementsByClassName("pkg-progress-install")[0].innerHTML = "软件安装进度:0%";
|
||||
|
||||
let succVal = (msg.succ / num) * 100;
|
||||
succVal = parseInt(succVal.toFixed(2));
|
||||
if (succVal > val)
|
||||
val = succVal;
|
||||
if (val > 99) val = 100;
|
||||
this.extInstallState.set(msg.depName, 12);
|
||||
|
||||
pkgInstallViews[0].value = val;
|
||||
document.getElementsByClassName("pkg-progress-install")[0].innerHTML = "软件安装进度:" + val + "%";
|
||||
this.checkScripts(msg);
|
||||
}
|
||||
else if (msg.type === "depInstallFail") {
|
||||
|
@ -484,6 +445,7 @@ class deployWindow {
|
|||
this.prevBtn = document.getElementById("prevStep") as HTMLButtonElement;
|
||||
this.cancelBtn = document.getElementById('cancel') as HTMLButtonElement;
|
||||
this.showTab(this.currentTab);
|
||||
this.removeAllListeners();
|
||||
this.registerEventListener();
|
||||
}
|
||||
|
||||
|
@ -586,26 +548,6 @@ class deployWindow {
|
|||
progress_view[0].value = 0;
|
||||
document.getElementsByClassName("progressinfo")[0].innerHTML = "安装进度:0%";
|
||||
|
||||
if (this.depList.length === 0) {
|
||||
let cname = document.getElementsByClassName("pkg-install-view")[0];
|
||||
if (cname) {
|
||||
document.getElementsByClassName("pkg-progress-install")[0].innerHTML = " ";
|
||||
cname.className = "grey-progress-view";
|
||||
}
|
||||
let grey_progress_view = document.getElementsByClassName("pkg-progress-install") as HTMLCollectionOf<HTMLProgressElement>;
|
||||
grey_progress_view[0].value = 0;
|
||||
// document.getElementsByClassName("pkg-progress-install")[0].style = "display: inline-block; background-color: gray;";
|
||||
}
|
||||
else {
|
||||
let cname = document.getElementsByClassName("pkg-install-view")[0];
|
||||
if (!cname) {
|
||||
document.getElementsByClassName("grey-progress-view")[0].className = "pkg-install-view";
|
||||
}
|
||||
let pkg_install_view = document.getElementsByClassName("pkg-install-view") as HTMLCollectionOf<HTMLProgressElement>;
|
||||
pkg_install_view[0].value = 0;
|
||||
document.getElementsByClassName("pkg-progress-install")[0].innerHTML = "软件安装进度:0%";
|
||||
}
|
||||
|
||||
let extPreElement = document.getElementById("extInstallLogPre");
|
||||
extPreElement!.innerHTML = "";
|
||||
|
||||
|
@ -620,9 +562,9 @@ class deployWindow {
|
|||
ipcRenderer.send('kylinide.installWizard.msg.process', installPkgMsg);
|
||||
ipcRenderer.send('kylinide.installWizard.init', { type: "writeJson", });
|
||||
} else if (this.onlineInstallTabArray[this.onlineInstallTabArrayIndex] === "onlineInstallTab4") {
|
||||
ipcRenderer.send('kylinide.installWizard.ok');
|
||||
console.log("onlineInstallTab4");
|
||||
this.removeAllListeners();
|
||||
ipcRenderer.send('kylinide.installWizard.skipWizard');
|
||||
console.log("onlineInstallTab4");
|
||||
return;
|
||||
}
|
||||
if (this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1) {
|
||||
|
@ -694,6 +636,7 @@ class deployWindow {
|
|||
// ipcRenderer.send('kylinide.installWizard.closeBefore', { type: "processterm" });
|
||||
}
|
||||
else {
|
||||
console.log("this -------------closeBtn");
|
||||
ipcRenderer.send('kylinide.installWizard.closeWizard', { type: "close" });
|
||||
this.removeAllListeners();
|
||||
}
|
||||
|
@ -798,47 +741,6 @@ class deployWindow {
|
|||
}
|
||||
}
|
||||
|
||||
//显示系统信息
|
||||
readOSInfo(os: string) {
|
||||
console.log('readosinf');
|
||||
const parentdiv = document.getElementById('osInfo') as HTMLDivElement;
|
||||
const parentdivshow = document.getElementById('osInfoShow') as HTMLDivElement;
|
||||
parentdiv.innerHTML = "";
|
||||
parentdivshow.innerHTML = "";
|
||||
const kyinfoPath = '/etc/.kyinfo';
|
||||
const osReleasePath = '/etc/os-release';
|
||||
let osinfo;
|
||||
if (!os) {
|
||||
osinfo = `<h3>操作系统信息</h3><p>操作系统检测脚本运行失败,未成功检测到操作系统类型</p>`
|
||||
} else {
|
||||
osinfo = `<h3>操作系统信息</h3><p>已检测到当前操作系统信息为:<span style="color:#1177BB;">${os}</span></p>`;
|
||||
}
|
||||
parentdiv.innerHTML = osinfo;
|
||||
|
||||
let data = "";
|
||||
let osdiv;
|
||||
const fs = require('fs');
|
||||
if (fs.existsSync(kyinfoPath)) {
|
||||
try {
|
||||
osdiv = `<p>判断依据:</p><p>cat /etc/.kyinfo</p>`
|
||||
data = fs.readFileSync(kyinfoPath, 'utf8');
|
||||
data = data.replace(/\n/g, '<br>');
|
||||
} catch (err) {
|
||||
}
|
||||
} else if (fs.existsSync(osReleasePath)) {
|
||||
try {
|
||||
osdiv = "操作系统信息:cat /etc/os-release"
|
||||
data = fs.readFileSync(osReleasePath, 'utf8');
|
||||
data = data.replace(/\n/g, '<br>');
|
||||
} catch (err) { }
|
||||
}
|
||||
if (osdiv == "" && data == "") {
|
||||
parentdivshow.innerHTML = "读取操作系统信息失败";
|
||||
} else {
|
||||
parentdivshow.innerHTML = `${osdiv}<p>${data}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
setFisrtClass(depDataObject: any, jsonSelectKey: string[]) {
|
||||
var form = document.getElementById("checkboxForm");
|
||||
// var depDataObject = JSON.parse(fs.readFileSync(depPath, 'utf-8'));
|
||||
|
@ -1100,8 +1002,7 @@ class deployWindow {
|
|||
type: "installScript",
|
||||
extList: this.extList,
|
||||
depList: this.depList,
|
||||
script: obj,
|
||||
dst: utils.configDir()
|
||||
script: obj
|
||||
};
|
||||
ipcRenderer.send("kylinide.installWizard.msg.process", installMsg);
|
||||
}
|
||||
|
|
|
@ -162,30 +162,25 @@ 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.removeListeners();
|
||||
this.registerListeners();
|
||||
}
|
||||
|
||||
//#region Register Listeners
|
||||
|
||||
private registerListeners(): void {
|
||||
//接收从渲染进程发送的消息
|
||||
logger.debug("注册界面监听时间");
|
||||
validatedIpcMain.on('kylinide.installWizard.helpLink', event => {
|
||||
listenerHelpLink = (event: IpcMainEvent) => {
|
||||
logger.info("打开帮助页面");
|
||||
this.openHelpLink();
|
||||
});
|
||||
validatedIpcMain.on('kylinide.installWizard.minw', event => {
|
||||
};
|
||||
listenerMiniWindow = (event: IpcMainEvent) => {
|
||||
logger.info("最小化窗口");
|
||||
this.minWindow();
|
||||
|
||||
});
|
||||
validatedIpcMain.on('kylinide.installWizard.closeWizard', event => {
|
||||
};
|
||||
listenerCloseWindow = (event: IpcMainEvent) => {
|
||||
logger.info("关闭窗口");
|
||||
this.closeWindow();
|
||||
};
|
||||
|
||||
});
|
||||
validatedIpcMain.on('kylinide.installWizard.msg.process', async (event, msg) => {
|
||||
listenerInstallProcess = async (event: IpcMainEvent, msg: any) => {
|
||||
if (msg.type === 'installExt') {
|
||||
|
||||
const logFile0 = this.installConfig + '/log/extInstall.1.log';
|
||||
|
@ -379,22 +374,286 @@ export class DeployMainService implements IDeployMainService {
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
validatedIpcMain.on('kylinide.installWizard.msg.deplist', (event, message) => {
|
||||
};
|
||||
listenerDepInfo = (event: IpcMainEvent, msg: any) => {
|
||||
this.depList = [];
|
||||
this.extList = [];
|
||||
// scriptList = [];
|
||||
this.depList = message.depList;
|
||||
this.extList = message.extList;
|
||||
this.DownSelectKey.configList = message.configList;
|
||||
this.depList = msg.depList;
|
||||
this.extList = msg.extList;
|
||||
this.DownSelectKey.configList = msg.configList;
|
||||
// scriptList = message.scriptList;
|
||||
this.extMap = {};
|
||||
};
|
||||
listenerCheckInstall = async (event: IpcMainEvent, msg: any) => {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// validatedIpcMain.on('kylinide.installWizard.skipWizard', event => {
|
||||
// logger.info("跳过操作");
|
||||
// })
|
||||
//检测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;
|
||||
|
||||
}
|
||||
|
||||
listenerDownExten = async (event: IpcMainEvent, message: any) => {
|
||||
|
||||
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(); // 释放信号量
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private removeListeners(): void {
|
||||
//接收从渲染进程发送的消息
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.helpLink', this.listenerHelpLink);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.minw', this.listenerMiniWindow);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.closeWizard', this.listenerCloseWindow);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.msg.process', this.listenerInstallProcess);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.msg.deplist', this.listenerDepInfo);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.checkInstall', this.listenerCheckInstall);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.downloadExt', this.listenerDownExten);
|
||||
}
|
||||
private registerListeners(): void {
|
||||
//接收从渲染进程发送的消息
|
||||
validatedIpcMain.on('kylinide.installWizard.helpLink', this.listenerHelpLink);
|
||||
validatedIpcMain.on('kylinide.installWizard.minw', this.listenerMiniWindow);
|
||||
validatedIpcMain.on('kylinide.installWizard.closeWizard', this.listenerCloseWindow);
|
||||
validatedIpcMain.on('kylinide.installWizard.msg.process', this.listenerInstallProcess);
|
||||
validatedIpcMain.on('kylinide.installWizard.msg.deplist', this.listenerDepInfo);
|
||||
validatedIpcMain.on('kylinide.installWizard.checkInstall', this.listenerCheckInstall);
|
||||
validatedIpcMain.on('kylinide.installWizard.downloadExt', this.listenerDownExten);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
@ -585,25 +844,25 @@ export class DeployMainService implements IDeployMainService {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.DeployWindow.on('close', () => {
|
||||
console.log("-----------------window close\n");
|
||||
this.DeployWindow = null;
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.skipWizard', listenerSkipWizard
|
||||
);
|
||||
validatedIpcMain.removeListener('kylinide.installWizard.init', listenerInit);
|
||||
DeployDisposables.dispose();
|
||||
|
||||
|
||||
});
|
||||
|
||||
validatedIpcMain.on('kylinide.installWizard.skipWizard', async (event) => {
|
||||
|
||||
const listenerSkipWizard = async (event: IpcMainEvent) => {
|
||||
logger.info("跳过配置");
|
||||
if (this.DeployWindow && this.DeployWindow != undefined) {
|
||||
this.DeployWindow.close();
|
||||
resolve(void 0);
|
||||
}
|
||||
});
|
||||
|
||||
validatedIpcMain.on('kylinide.installWizard.init', async (event, msg) => {
|
||||
}
|
||||
validatedIpcMain.on('kylinide.installWizard.skipWizard', listenerSkipWizard
|
||||
);
|
||||
const listenerInit = async (event: IpcMainEvent, msg: any) => {
|
||||
console.log("main on kylinide.installWizard.init");
|
||||
let selectPageShow = 0;
|
||||
let message: string = "";
|
||||
|
@ -803,253 +1062,8 @@ export class DeployMainService implements IDeployMainService {
|
|||
} else if (msg.type === 'writeKey') {
|
||||
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(); // 释放信号量
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
validatedIpcMain.on('kylinide.installWizard.init', listenerInit);
|
||||
|
||||
}
|
||||
if (this.DeployWindow) {
|
||||
|
@ -1085,8 +1099,6 @@ export class DeployMainService implements IDeployMainService {
|
|||
icon: join(this.environmentMainService.appRoot, 'resources/linux/code.png'),
|
||||
frame: false
|
||||
} as BrowserWindowConstructorOptions & { experimentalDarkMode: true })
|
||||
// window.setAutoHideMenuBar(true);
|
||||
// window.setMenuBarVisibility(false);
|
||||
return window;
|
||||
}
|
||||
private getDeployWindowPosition(defaultWidth: number, defaultHeight: number): IStrictWindowState {
|
||||
|
@ -1526,10 +1538,6 @@ export class DeployMainService implements IDeployMainService {
|
|||
}
|
||||
return { osFile, data }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// function isStrictWindowState(obj: unknown): obj is IStrictWindowState {
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// import * as os from 'os';
|
||||
// import * as fs from 'fs';
|
||||
|
||||
//获取全局变量g_index.json下载网络
|
||||
export function get_g_index_url() {
|
||||
let { gIndexUrl } = require('../../../../../../product.json');
|
||||
return gIndexUrl;
|
||||
}
|
||||
|
||||
export function configDir() {
|
||||
// 获取用户目录
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const userHome = os.homedir();
|
||||
// 创建日志目录
|
||||
const configDir = `${userHome}/.config/Kylin-Code/installconfig`;
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir, { recursive: true }); // 递归创建目录
|
||||
}
|
||||
return configDir;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue