添加取消功能
This commit is contained in:
parent
8ea50378d9
commit
1fb04ca772
|
@ -108,7 +108,7 @@ import { Semaphore } from "async-mutex";
|
|||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { spawn } from 'child_process';
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
|
||||
/**
|
||||
* The main VS Code application. There will only ever be one instance,
|
||||
|
@ -453,7 +453,7 @@ export class CodeApplication extends Disposable {
|
|||
});
|
||||
|
||||
//关闭安装引导界面
|
||||
ipcMain.on('kylinide.installWizard.closeWizard', (evevt, arg) => {
|
||||
ipcMain.on('kylinide.installWizard.closeWizard', (evevt, msg) => {
|
||||
if (this.win) {
|
||||
this.win.close();
|
||||
}
|
||||
|
@ -1339,9 +1339,13 @@ export class CodeApplication extends Disposable {
|
|||
let extMap: Record<string, string> = {};
|
||||
let depList: string[] = [];
|
||||
let extList: string[] = [];
|
||||
let installFsWatcher: fs.FSWatcher;
|
||||
let extlogFsWatcher: fs.FSWatcher;
|
||||
let pkglogFsWatcher: fs.FSWatcher;
|
||||
//文件监听;
|
||||
let installFsWatcher: fs.FSWatcher | null;
|
||||
let extlogFsWatcher: fs.FSWatcher | null;
|
||||
let pkglogFsWatcher: fs.FSWatcher | null;
|
||||
//执行安装脚本的进程号;
|
||||
let installProcessId: ChildProcess;
|
||||
|
||||
// let scriptList: {}[] = [];
|
||||
//electron生命周期 监听did-finish-load事件
|
||||
this.win.webContents.on('did-finish-load', async function () {
|
||||
|
@ -1660,47 +1664,48 @@ export class CodeApplication extends Disposable {
|
|||
fs.writeFileSync(logFile0, '');
|
||||
}
|
||||
//监听install pkg输出信息
|
||||
fs.watch(logFile0, (eventType, filename) => {
|
||||
if (eventType === 'change') {
|
||||
// 获取文件的当前大小
|
||||
const stats = fs.statSync(logFile0);
|
||||
const currentSize = stats.size;
|
||||
if (lastLogPosition === 0 && stats.size > 0) {
|
||||
const startDownloadExtMsg = {
|
||||
type: "extDownloadInit",
|
||||
}
|
||||
if (that.win)
|
||||
that.win.webContents.send("kylinide.installWizard.msg", startDownloadExtMsg)
|
||||
pkglogFsWatcher =
|
||||
fs.watch(logFile0, (eventType, filename) => {
|
||||
if (eventType === 'change') {
|
||||
// 获取文件的当前大小
|
||||
const stats = fs.statSync(logFile0);
|
||||
const currentSize = stats.size;
|
||||
if (lastLogPosition === 0 && stats.size > 0) {
|
||||
const startDownloadExtMsg = {
|
||||
type: "extDownloadInit",
|
||||
}
|
||||
if (that.win)
|
||||
that.win.webContents.send("kylinide.installWizard.msg", startDownloadExtMsg)
|
||||
|
||||
const extlogFile0 = installConfig + '/log/extInstall.1.log';
|
||||
fs.writeFileSync(extlogFile0, '');
|
||||
const extlogFile0 = installConfig + '/log/extInstall.1.log';
|
||||
fs.writeFileSync(extlogFile0, '');
|
||||
}
|
||||
|
||||
// 计算更新部分的大小
|
||||
const updateSize = currentSize - lastLogPosition;
|
||||
if (updateSize <= 0) return;
|
||||
|
||||
// 读取更新部分的内容
|
||||
const buffer = Buffer.alloc(updateSize);
|
||||
const fileDescriptor = fs.openSync(logFile0, 'r');
|
||||
fs.readSync(fileDescriptor, buffer, 0, updateSize, lastLogPosition);
|
||||
fs.closeSync(fileDescriptor);
|
||||
|
||||
// 将更新部分的内容转换为字符串并输出
|
||||
const updatedContent = buffer.toString('utf8');
|
||||
|
||||
// 更新上一次读取的位置
|
||||
lastLogPosition = currentSize;
|
||||
const installMsg = {
|
||||
type: "installLogPre",
|
||||
data: updatedContent
|
||||
};
|
||||
|
||||
if (that.win)
|
||||
that.win.webContents.send("kylinide.installWizard.msg", installMsg);
|
||||
}
|
||||
|
||||
// 计算更新部分的大小
|
||||
const updateSize = currentSize - lastLogPosition;
|
||||
if (updateSize <= 0) return;
|
||||
|
||||
// 读取更新部分的内容
|
||||
const buffer = Buffer.alloc(updateSize);
|
||||
const fileDescriptor = fs.openSync(logFile0, 'r');
|
||||
fs.readSync(fileDescriptor, buffer, 0, updateSize, lastLogPosition);
|
||||
fs.closeSync(fileDescriptor);
|
||||
|
||||
// 将更新部分的内容转换为字符串并输出
|
||||
const updatedContent = buffer.toString('utf8');
|
||||
|
||||
// 更新上一次读取的位置
|
||||
lastLogPosition = currentSize;
|
||||
const installMsg = {
|
||||
type: "installLogPre",
|
||||
data: updatedContent
|
||||
};
|
||||
|
||||
if (that.win)
|
||||
that.win.webContents.send("kylinide.installWizard.msg", installMsg);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//检测ext 安装信息文件变化
|
||||
extlogFsWatcher =
|
||||
|
@ -1849,11 +1854,21 @@ export class CodeApplication extends Disposable {
|
|||
|
||||
ipcMain.on("kylinide.installWizard.removeFileLister", async (event, msg) => {
|
||||
if (msg.type == "installFile") {
|
||||
installFsWatcher.close();
|
||||
if (installFsWatcher) {
|
||||
installFsWatcher.close();
|
||||
installFsWatcher = null;
|
||||
}
|
||||
} else if (msg.type == "extFile") {
|
||||
extlogFsWatcher.close();
|
||||
if (extlogFsWatcher) {
|
||||
extlogFsWatcher.close();
|
||||
extlogFsWatcher = null;
|
||||
}
|
||||
|
||||
} else if (msg.type == "pkgFile") {
|
||||
pkglogFsWatcher.close();
|
||||
if (pkglogFsWatcher) {
|
||||
pkglogFsWatcher.close();
|
||||
pkglogFsWatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1865,7 +1880,7 @@ export class CodeApplication extends Disposable {
|
|||
let extDownloadUrlList = [];
|
||||
extDownloadPath = installConfig + '/Download/'
|
||||
|
||||
const concurrencyLimit = 5; // 并发限制数量
|
||||
const concurrencyLimit = 1; // 并发限制数量
|
||||
const semaphore = new Semaphore(concurrencyLimit);
|
||||
|
||||
extList.forEach(async (val) => {
|
||||
|
@ -1977,9 +1992,6 @@ export class CodeApplication extends Disposable {
|
|||
} catch (error) {
|
||||
console.error(`执行出错: ${error.message}`);
|
||||
}
|
||||
}
|
||||
else if (msg.type === 'installPkgStop') {
|
||||
|
||||
}
|
||||
else if (msg.type === 'installPkg') {
|
||||
console.log("kylinide.installWizard.msg.process:installPkg");
|
||||
|
@ -2054,7 +2066,7 @@ export class CodeApplication extends Disposable {
|
|||
if (depList.length === 0) return;
|
||||
|
||||
depList.forEach((packageName) => {
|
||||
const command = `apt-get install -y ${packageName} >> ${logFile0}\necho $? >> ${resultFile}\n`;
|
||||
const command = `apt-get install -y ${packageName} >> ${logFile0};\necho $? >> ${resultFile};\nsleep 2;\n`;
|
||||
fs.appendFileSync(installFile, command);
|
||||
});
|
||||
|
||||
|
@ -2106,6 +2118,48 @@ export class CodeApplication extends Disposable {
|
|||
});
|
||||
|
||||
}
|
||||
} else if (msg.type == "cancel") {
|
||||
//1.结束监听
|
||||
//2.结束正在执行的进程,下载,插件安装,软件包安装
|
||||
if (installProcessId && installProcessId.pid && installProcessId.exitCode == null && flagPkexec == 0) {
|
||||
console.log("取消安装before");
|
||||
// var killcommand = `pkexec sudo pkill -TERM -P ${installProcessId.pid}`;
|
||||
var killcommand = `pkexec sudo pkill -f 'bash ${installConfig}/install.sh'`;
|
||||
const sudokill = spawn(killcommand, { shell: true, stdio: 'inherit' });
|
||||
|
||||
sudokill.on('exit', (code, signal) => {
|
||||
if (code == 127) {
|
||||
console.log('授权失败', code);
|
||||
} else {
|
||||
|
||||
console.log("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
|
||||
if (this.win) {
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'installFile' });
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'extFile' });
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'pkgFile' });
|
||||
}
|
||||
installQueue.splice(0);
|
||||
//结束插件下载及安装
|
||||
if (that.win) {
|
||||
that.win.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" });
|
||||
}
|
||||
}
|
||||
console.log('kill Exit code:', code);
|
||||
});
|
||||
console.log("取消安装after");
|
||||
} else {
|
||||
console.log("XXXXXXXXXXXXXXXXXXXXXXxx");
|
||||
if (this.win) {
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'installFile' });
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'extFile' });
|
||||
this.win.webContents.send("kylinide.installWizard.removeFileLister", { type: 'pkgFile' });
|
||||
}
|
||||
installQueue.splice(0);
|
||||
//结束插件下载及安装
|
||||
if (that.win) {
|
||||
that.win.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2154,16 +2208,28 @@ export class CodeApplication extends Disposable {
|
|||
await executeNextInstall(); // 继续执行下一个消息
|
||||
}
|
||||
|
||||
var flagPkexec = 0;
|
||||
function executeScriptWithPkexec(scriptPath: string) {
|
||||
flagPkexec = 0;
|
||||
console.log("executeScriptWithPkexec");
|
||||
try {
|
||||
const pkexecCommand = `pkexec sudo bash ${scriptPath}`;
|
||||
spawn(pkexecCommand, { shell: true, stdio: 'inherit' });
|
||||
console.log(`脚本执行成功: ${scriptPath}`);
|
||||
return true;
|
||||
installProcessId =
|
||||
spawn(pkexecCommand, { shell: true, stdio: 'inherit' });
|
||||
|
||||
installProcessId.on('exit', (code, signal) => {
|
||||
flagPkexec++;
|
||||
console.log('Exit code:', code);
|
||||
if (code == 127) {
|
||||
//授权失败,结束安装。
|
||||
if (that.win) {
|
||||
that.win.webContents.send("kylinide.installWizard.Auth", { type: "pkgNotAuth" });
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`执行脚本时出错: ${error.message}`);
|
||||
return false;
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2186,7 +2252,7 @@ export class CodeApplication extends Disposable {
|
|||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(new Error(`Command failed with exit code ${code}`));
|
||||
reject(new Error(`Command failed with exit code ${code} `));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -2199,8 +2265,8 @@ export class CodeApplication extends Disposable {
|
|||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
// console.log(`stdout: ${stdout}`);
|
||||
// console.error(`stderr1: ${stderr}`);
|
||||
// console.log(`stdout: ${ stdout } `);
|
||||
// console.error(`stderr1: ${ stderr } `);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
@ -2214,6 +2280,8 @@ export class CodeApplication extends Disposable {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private replaceBaseUrl(url: string, baseurl: string) {
|
||||
if (url.startsWith("base-url:")) {
|
||||
url = url.replace("base-url:", baseurl);
|
||||
|
@ -2314,11 +2382,11 @@ export class CodeApplication extends Disposable {
|
|||
//获取到判断操作系统的脚本文件
|
||||
var match_script_file_name = g_index_localDataObject["match-script"]["file_name"];
|
||||
var match_script_file_sign = g_index_localDataObject["match-script"]["sign-md5"];
|
||||
var match_script_filePath = path.join(configDir, `./${match_script_file_name}`);
|
||||
var match_script_filePath = path.join(configDir, `${match_script_file_name}`);
|
||||
//获取到存放插件仓库的配置文件
|
||||
var match_ext_file_name = g_index_localDataObject["ext-file"]["file_name"];
|
||||
var match_ext_file_sign = g_index_localDataObject["ext-file"]["sign-md5"];
|
||||
var match_ext_filePath = path.join(configDir, `./${match_ext_file_name}`);
|
||||
var match_ext_filePath = path.join(configDir, `${match_ext_file_name}`);
|
||||
|
||||
//校验本地数据是否有问题
|
||||
if (!this.versify(`${match_script_filePath}`, match_script_file_sign)) {
|
||||
|
|
|
@ -7,5 +7,6 @@
|
|||
"okStep": "OK",
|
||||
"onlineInstalllabel": "Online Install",
|
||||
"lablenotNow": "Skip(Configured by myself)",
|
||||
"finish":"Finish"
|
||||
"finish":"Finish",
|
||||
"cancel":"Cancel"
|
||||
}
|
||||
|
|
|
@ -7,5 +7,6 @@
|
|||
"okStep": "确 定",
|
||||
"onlineInstalllabel": "在线安装",
|
||||
"lablenotNow": "跳过(我自己配置)",
|
||||
"finish":"结束"
|
||||
"finish":"结束",
|
||||
"cancel":"取消"
|
||||
}
|
||||
|
|
|
@ -422,7 +422,8 @@ input[readonly] {
|
|||
} */
|
||||
|
||||
button#prevStep:disabled ,
|
||||
button#nextStep:disabled
|
||||
button#nextStep:disabled,
|
||||
button#cancel:disabled
|
||||
{
|
||||
background-color: gray;
|
||||
border-color: gray;
|
||||
|
|
|
@ -215,9 +215,8 @@
|
|||
</div>
|
||||
<div class="btn-group right" style="float: right;">
|
||||
<button class="prevStep" id="prevStep"></button>
|
||||
<button class="cancel" id="cancel" style="display:none"></button>
|
||||
<button class="nextStep" id="nextStep" type="submit"></button>
|
||||
<button class="confirm" id="confirm" type="submit" style="display:none"></button>
|
||||
<button class="complete" id="confirm" type="submit" style="display:none"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -40,7 +40,14 @@ let progressNum = 0;
|
|||
* 窗口关闭按钮动作
|
||||
*/
|
||||
document.getElementById('closeBtn').addEventListener('click', () => {
|
||||
ipcRenderer.send('kylinide.installWizard.closeWizard', { isFirstLoad });
|
||||
if (onlineInstallRadio.checked && onlineInstallTabArray[onlineInstallTabArrayIndex] == "onlineInstallTab4") {
|
||||
ipcRenderer.send('kylinide.installWizard.closeBefore', { type: "processterm" });
|
||||
}
|
||||
else {
|
||||
ipcRenderer.send('kylinide.installWizard.closeWizard', { type: "close" });
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
document.getElementById('helpLink').addEventListener('click', (e) => {
|
||||
|
@ -65,6 +72,11 @@ document.getElementById('selectConfigPath').addEventListener('click', () => {
|
|||
console.log('get configPath');
|
||||
ipcRenderer.send('kylinide.installWizard.justDownLoad', { type: "getPath" });
|
||||
});
|
||||
document.getElementById('cancel').addEventListener('click', () => {
|
||||
console.log('cancel');
|
||||
// ipcRenderer.removeAllListeners('kylinide.installWizard.msg');
|
||||
ipcRenderer.send('kylinide.installWizard.msg.process', { type: "cancel" });
|
||||
});
|
||||
|
||||
|
||||
// 添加点击事件监听器
|
||||
|
@ -122,7 +134,8 @@ function setDisplayLanguage() {
|
|||
document.getElementById('lablenotNow').innerText = setLanguage('lablenotNow');
|
||||
document.getElementById("localInstall").innerText = setLanguage('localInstall');
|
||||
document.getElementById("justDownload").innerText = setLanguage('justDownload');
|
||||
document.getElementById("confirm").innerText = setLanguage('okStep');
|
||||
document.getElementById('cancel').innerText = setLanguage('cancel');
|
||||
// document.getElementById("confirm").innerText = setLanguage('okStep');
|
||||
}
|
||||
|
||||
ipcRenderer.on('init-data', (event, arg) => {
|
||||
|
@ -459,11 +472,14 @@ function nextPrev(n) {
|
|||
if (onlineInstallTabArray[onlineInstallTabArrayIndex] === "onlineInstallTab3") {
|
||||
document.getElementById('nextStep').disabled = true;
|
||||
document.getElementById('nextStep').innerHTML = setLanguage('okStep');
|
||||
|
||||
}
|
||||
if (onlineInstallTabArray[onlineInstallTabArrayIndex] === "onlineInstallTab4") {
|
||||
document.getElementById('prevStep').disabled = true;
|
||||
document.getElementById('nextStep').disabled = true;
|
||||
document.getElementById('nextStep').innerHTML = setLanguage('okStep');
|
||||
document.getElementById('cancel').innerText = setLanguage('cancel');
|
||||
document.getElementById('cancel').style.display = "inline";
|
||||
}
|
||||
} else if (localInstallRadio.checked) {
|
||||
justDownLoadTabArrayIndex = 0;
|
||||
|
@ -891,14 +907,64 @@ ipcRenderer.on('kylinide.installWizard.msg', (event, msg) => {
|
|||
|
||||
document.getElementById("nextStep").innerText = setLanguage("finish");
|
||||
document.getElementById("nextStep").disabled = false;
|
||||
document.getElementById("cancel").disabled = true;
|
||||
logShow = 0;
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "extFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "pkgFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "installFile" });
|
||||
|
||||
}
|
||||
}
|
||||
// preElement.scrollTop = preElement.scrollHeight;
|
||||
});
|
||||
|
||||
ipcRenderer.on("kylinide.installWizard.Auth", (event, msg) => {
|
||||
if (msg.type == "pkgNotAuth") {
|
||||
finishFlag = 0;
|
||||
let preFinish = document.getElementById("finishPage");
|
||||
let showContext = preFinish.innerHTML;
|
||||
showContext += "授权失败,结束安装\n";
|
||||
showContext += "点击结束按钮退出安装向导\n"
|
||||
preFinish.innerHTML = showContext;
|
||||
preFinish.style.display = 'block';
|
||||
document.getElementById("installLogPre").style.display = 'none';
|
||||
document.getElementById("detailInstallPre").style.display = 'none';
|
||||
document.getElementById("extInstallLogPre").style.display = 'none';
|
||||
|
||||
document.getElementById("nextStep").innerText = setLanguage("finish");
|
||||
document.getElementById("nextStep").disabled = false;
|
||||
document.getElementById("cancel").disabled = true;
|
||||
logShow = 0;
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "extFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "pkgFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "installFile" });
|
||||
removeAllListeners();
|
||||
}
|
||||
});
|
||||
ipcRenderer.on("kylinide.installWizard.cancelinstall", (event, msg) => {
|
||||
if (msg.type == "cancelinstall") {
|
||||
finishFlag = 0;
|
||||
let preFinish = document.getElementById("finishPage");
|
||||
let showContext = preFinish.innerHTML;
|
||||
showContext += "取消安装\n";
|
||||
showContext += "点击结束按钮退出安装向导\n"
|
||||
preFinish.innerHTML = showContext;
|
||||
preFinish.style.display = 'block';
|
||||
document.getElementById("installLogPre").style.display = 'none';
|
||||
document.getElementById("detailInstallPre").style.display = 'none';
|
||||
document.getElementById("extInstallLogPre").style.display = 'none';
|
||||
|
||||
document.getElementById("nextStep").innerText = setLanguage("finish");
|
||||
document.getElementById("nextStep").disabled = false;
|
||||
document.getElementById("cancel").disabled = true;
|
||||
logShow = 0;
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "extFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "pkgFile" });
|
||||
ipcRenderer.send("kylinide.installWizard.removeFileLister", { type: "installFile" });
|
||||
removeAllListeners();
|
||||
}
|
||||
})
|
||||
|
||||
//根据key值获取value
|
||||
function getNameFromKey(key) {
|
||||
let name = '';
|
||||
|
@ -1028,4 +1094,5 @@ function removeAllListeners() {
|
|||
ipcRenderer.removeAllListeners('message-to-jsb');
|
||||
ipcRenderer.removeAllListeners('kylinide.installWizard.msg');
|
||||
ipcRenderer.removeAllListeners('kylinide.installWizard.removeFileLister');
|
||||
ipcRenderer.removeAllListeners('kylinide.installWizard.Auth');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue