From 2a2a520b142a218095d2c5d2d86b4444b9afff21 Mon Sep 17 00:00:00 2001 From: dinglili Date: Fri, 31 May 2024 16:09:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9B=91=E5=90=AC=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sandbox/electron-sandbox/deploypreload.js | 8 + .../sandbox/electron-sandbox/electronTypes.ts | 1 + .../deploy/deployWindow-dev.html | 16 - .../deploy/deployWindowMain.ts | 111 +-- .../issue/electron-main/deployMainService.ts | 924 +++++++++--------- src/vs/platform/issue/electron-main/utils.ts | 23 - 6 files changed, 481 insertions(+), 602 deletions(-) delete mode 100644 src/vs/platform/issue/electron-main/utils.ts diff --git a/src/vs/base/parts/sandbox/electron-sandbox/deploypreload.js b/src/vs/base/parts/sandbox/electron-sandbox/deploypreload.js index 7b1fe840..4d33c76a 100644 --- a/src/vs/base/parts/sandbox/electron-sandbox/deploypreload.js +++ b/src/vs/base/parts/sandbox/electron-sandbox/deploypreload.js @@ -183,6 +183,14 @@ ipcRenderer.removeListener(channel, listener); + return this; + }, + + removeAllListeners(channel) { + validateIPC(channel); + + ipcRenderer.removeAllListeners(channel); + return this; } }, diff --git a/src/vs/base/parts/sandbox/electron-sandbox/electronTypes.ts b/src/vs/base/parts/sandbox/electron-sandbox/electronTypes.ts index d32188d1..c76b2790 100644 --- a/src/vs/base/parts/sandbox/electron-sandbox/electronTypes.ts +++ b/src/vs/base/parts/sandbox/electron-sandbox/electronTypes.ts @@ -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, diff --git a/src/vs/code/electron-sandbox/deploy/deployWindow-dev.html b/src/vs/code/electron-sandbox/deploy/deployWindow-dev.html index 03c26ff4..a907b83b 100644 --- a/src/vs/code/electron-sandbox/deploy/deployWindow-dev.html +++ b/src/vs/code/electron-sandbox/deploy/deployWindow-dev.html @@ -128,8 +128,6 @@
- -
@@ -143,20 +141,6 @@
- - - - -
diff --git a/src/vs/code/electron-sandbox/deploy/deployWindowMain.ts b/src/vs/code/electron-sandbox/deploy/deployWindowMain.ts index c845cf70..61e0a938 100644 --- a/src/vs/code/electron-sandbox/deploy/deployWindowMain.ts +++ b/src/vs/code/electron-sandbox/deploy/deployWindowMain.ts @@ -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; - 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; - 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; - 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; - 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; - 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 = `

操作系统信息

操作系统检测脚本运行失败,未成功检测到操作系统类型

` - } else { - osinfo = `

操作系统信息

已检测到当前操作系统信息为:${os}

`; - } - parentdiv.innerHTML = osinfo; - - let data = ""; - let osdiv; - const fs = require('fs'); - if (fs.existsSync(kyinfoPath)) { - try { - osdiv = `

判断依据:

cat /etc/.kyinfo

` - data = fs.readFileSync(kyinfoPath, 'utf8'); - data = data.replace(/\n/g, '
'); - } catch (err) { - } - } else if (fs.existsSync(osReleasePath)) { - try { - osdiv = "操作系统信息:cat /etc/os-release" - data = fs.readFileSync(osReleasePath, 'utf8'); - data = data.replace(/\n/g, '
'); - } catch (err) { } - } - if (osdiv == "" && data == "") { - parentdivshow.innerHTML = "读取操作系统信息失败"; - } else { - parentdivshow.innerHTML = `${osdiv}

${data}

`; - } - } - 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); } diff --git a/src/vs/platform/issue/electron-main/deployMainService.ts b/src/vs/platform/issue/electron-main/deployMainService.ts index a4c6edd3..e8e0b8bf 100644 --- a/src/vs/platform/issue/electron-main/deployMainService.ts +++ b/src/vs/platform/issue/electron-main/deployMainService.ts @@ -162,239 +162,498 @@ 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 => { - logger.info("打开帮助页面"); - this.openHelpLink(); - }); - validatedIpcMain.on('kylinide.installWizard.minw', event => { - logger.info("最小化窗口"); - this.minWindow(); + listenerHelpLink = (event: IpcMainEvent) => { + logger.info("打开帮助页面"); + this.openHelpLink(); + }; + listenerMiniWindow = (event: IpcMainEvent) => { + logger.info("最小化窗口"); + this.minWindow(); + }; + listenerCloseWindow = (event: IpcMainEvent) => { + logger.info("关闭窗口"); + this.closeWindow(); + }; - }); - validatedIpcMain.on('kylinide.installWizard.closeWizard', event => { - logger.info("关闭窗口"); - this.closeWindow(); + listenerInstallProcess = async (event: IpcMainEvent, msg: any) => { + if (msg.type === 'installExt') { - }); - validatedIpcMain.on('kylinide.installWizard.msg.process', async (event, msg) => { - if (msg.type === 'installExt') { + const logFile0 = this.installConfig + '/log/extInstall.1.log'; - const logFile0 = this.installConfig + '/log/extInstall.1.log'; + if (!fs.existsSync(logFile0)) { + fs.mkdirSync(this.installConfig + "/log", { recursive: true }); + } - if (!fs.existsSync(logFile0)) { - fs.mkdirSync(this.installConfig + "/log", { recursive: true }); + try { + const installItem = this.extDownloadPath + msg.downloadDone; + const installCommand = "kylin-code --install-extension " + installItem; + if (this.installQueue.length === 0) { + this.installQueue.push({ installCommand, msg }); + await this.executeNextInstall(); + } + else { + this.installQueue.push({ installCommand, msg }); } - try { - const installItem = this.extDownloadPath + msg.downloadDone; - const installCommand = "kylin-code --install-extension " + installItem; - if (this.installQueue.length === 0) { - this.installQueue.push({ installCommand, msg }); - await this.executeNextInstall(); - } - else { - this.installQueue.push({ installCommand, msg }); + } catch (error) { + console.error(`执行出错: ${error.message}`); + } + } + else if (msg.type === 'installPkg') { + console.log("kylinide.installWizard.msg.process:installPkg"); + const extlogFile = this.installConfig + '/log/extInstall.log'; + this.backupLogFile(extlogFile) + const extlogFile0 = this.installConfig + '/log/extInstall.1.log'; + fs.writeFileSync(extlogFile0, ''); + + if (this.depList.length === 0) { + const startDownloadExtMsg = { + type: "extDownloadInit", + } + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", startDownloadExtMsg); + this.lastExtLogPosition = 0; + + 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) + } - } catch (error) { - console.error(`执行出错: ${error.message}`); + }); + return; + } + + this.lastLogPosition = 0; + this.lastExtLogPosition = 0; + const logFile = this.installConfig + '/log/install.log'; + const resultFile = this.installConfig + '/resultFile'; + const installFile = this.installConfig + '/install.sh'; + const logFile0 = this.installConfig + '/log/install.1.log'; + this.backupLogFile(logFile); + + try { + fs.writeFileSync(resultFile, ''); + fs.writeFileSync(installFile, ''); + fs.writeFileSync(logFile0, ''); + const installMsg = { + type: "depStartInstall", + depName: 'depStartInstall' + }; + + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg) + + if (this.depList.length === 0) return; + + this.depList.forEach((packageName) => { + const command = `apt-get install -y ${packageName} >> ${logFile0};\necho $? >> ${resultFile};\n`; + fs.appendFileSync(installFile, command); + }); + + this.executeScriptWithPkexec(installFile); + + } catch (error) { + console.log(error); + } + } + else if (msg.type === 'installScript') { + if (msg.script['file_name'].endsWith(".js")) { + try { + await this.loadAndInvokeFunction(this.selectObject.dirPath + '/' + msg.script['file_name'], "main"); + const scriptMsg = { + type: "scriptExecSucc", + depName: msg.script['file_name'] + }; + logger.info("脚本执行成功" + this.selectObject.dirPath + '/' + msg.script['file_name']); + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) + } catch { + const scriptMsg = { + type: "scriptExecFail", + depName: msg.script['file_name'] + }; + logger.info("脚本执行失败" + this.selectObject.dirPath + '/' + msg.script['file_name']); + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) + } + } else if (msg.script['file_name'].endsWith(".sh")) { + let command = "sh " + this.selectObject.dirPath + '/' + msg.script['file_name']; + // await executeCommand(command); + this.executeCommand(command).then(res => { + const scriptMsg = { + type: "scriptExecSucc", + depName: msg.script['file_name'] + }; + logger.info("脚本执行成功" + this.selectObject.dirPath + '/' + msg.script['file_name']); + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) + }).catch(error => { + const scriptMsg = { + type: "scriptExecFail", + depName: msg.script['file_name'] + }; + logger.info("脚本执行失败" + this.selectObject.dirPath + '/' + msg.script['file_name']); + if (this.DeployWindow) + this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) + }); + + } + } + else if (msg.type == "cancel") { + //1.结束监听 + //2.结束正在执行的进程,下载,插件安装,软件包安装 + if (this.installProcessId && this.installProcessId.pid && this.installProcessId.exitCode == null && this.flagPkexec == 0) { + console.log("取消安装before"); + // 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' }); + + sudokill.on('exit', (code, signal) => { + if (code == 127) { + console.log('授权失败', code); + logger.error("取消安装授权失败"); + } else { + 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); + //结束插件下载及安装 + if (this.DeployWindow) { + this.DeployWindow.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" }); + } + } + console.log('kill Exit code:', code); + }); + console.log("取消安装after"); + } else { + 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.cancelFlag = true; + this.installQueue.splice(0); + //结束插件下载及安装 + if (this.DeployWindow) { + this.DeployWindow.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" }); } } - else if (msg.type === 'installPkg') { - console.log("kylinide.installWizard.msg.process:installPkg"); - const extlogFile = this.installConfig + '/log/extInstall.log'; - this.backupLogFile(extlogFile) - const extlogFile0 = this.installConfig + '/log/extInstall.1.log'; - fs.writeFileSync(extlogFile0, ''); + } - if (this.depList.length === 0) { - const startDownloadExtMsg = { - type: "extDownloadInit", - } - if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", startDownloadExtMsg); - this.lastExtLogPosition = 0; - - 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) + }; + listenerDepInfo = (event: IpcMainEvent, msg: any) => { + this.depList = []; + this.extList = []; + // scriptList = []; + 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) - }); - return; - } + const extlogFile0 = this.installConfig + '/log/extInstall.1.log'; + fs.writeFileSync(extlogFile0, ''); + } - this.lastLogPosition = 0; - this.lastExtLogPosition = 0; - const logFile = this.installConfig + '/log/install.log'; - const resultFile = this.installConfig + '/resultFile'; - const installFile = this.installConfig + '/install.sh'; - const logFile0 = this.installConfig + '/log/install.1.log'; - this.backupLogFile(logFile); + // 计算更新部分的大小 + const updateSize = currentSize - this.lastLogPosition; + if (updateSize <= 0) return; - try { - fs.writeFileSync(resultFile, ''); - fs.writeFileSync(installFile, ''); - fs.writeFileSync(logFile0, ''); + // 读取更新部分的内容 + 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: "depStartInstall", - depName: 'depStartInstall' + type: "installLogPre", + data: updatedContent }; if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg) - - if (this.depList.length === 0) return; - - this.depList.forEach((packageName) => { - const command = `apt-get install -y ${packageName} >> ${logFile0};\necho $? >> ${resultFile};\n`; - fs.appendFileSync(installFile, command); - }); - - this.executeScriptWithPkexec(installFile); - - } catch (error) { - console.log(error); + this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg); } - } - else if (msg.type === 'installScript') { - if (msg.script['file_name'].endsWith(".js")) { - try { - await this.loadAndInvokeFunction(this.selectObject.dirPath + '/' + msg.script['file_name'], "main"); - const scriptMsg = { - type: "scriptExecSucc", - depName: msg.script['file_name'] - }; - logger.info("脚本执行成功" + this.selectObject.dirPath + '/' + msg.script['file_name']); - if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) - } catch { - const scriptMsg = { - type: "scriptExecFail", - depName: msg.script['file_name'] - }; - logger.info("脚本执行失败" + this.selectObject.dirPath + '/' + msg.script['file_name']); - if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) + + }); + + //检测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; } - } else if (msg.script['file_name'].endsWith(".sh")) { - let command = "sh " + this.selectObject.dirPath + '/' + msg.script['file_name']; - // await executeCommand(command); - this.executeCommand(command).then(res => { - const scriptMsg = { - type: "scriptExecSucc", - depName: msg.script['file_name'] - }; - logger.info("脚本执行成功" + this.selectObject.dirPath + '/' + msg.script['file_name']); - if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) - }).catch(error => { - const scriptMsg = { - type: "scriptExecFail", - depName: msg.script['file_name'] - }; - logger.info("脚本执行失败" + this.selectObject.dirPath + '/' + msg.script['file_name']); - if (this.DeployWindow) - this.DeployWindow.webContents.send("kylinide.installWizard.msg", scriptMsg) - }); + // 计算文件变化的部分的偏移量 + 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++; + }); } - else if (msg.type == "cancel") { - //1.结束监听 - //2.结束正在执行的进程,下载,插件安装,软件包安装 - if (this.installProcessId && this.installProcessId.pid && this.installProcessId.exitCode == null && this.flagPkexec == 0) { - console.log("取消安装before"); - // 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.startInstallDepWatch = 1; - sudokill.on('exit', (code, signal) => { - if (code == 127) { - console.log('授权失败', code); - logger.error("取消安装授权失败"); + } + + 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 { - 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); - //结束插件下载及安装 - if (this.DeployWindow) { - this.DeployWindow.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" }); - } + 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); } - console.log('kill Exit code:', code); + }).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); + }); - console.log("取消安装after"); - } else { - 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.cancelFlag = true; - this.installQueue.splice(0); - //结束插件下载及安装 - if (this.DeployWindow) { - this.DeployWindow.webContents.send("kylinide.installWizard.cancelinstall", { type: "cancelinstall" }); - } } + } 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.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("跳过操作"); - // }) + } + + 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 { diff --git a/src/vs/platform/issue/electron-main/utils.ts b/src/vs/platform/issue/electron-main/utils.ts deleted file mode 100644 index dbd9f7cb..00000000 --- a/src/vs/platform/issue/electron-main/utils.ts +++ /dev/null @@ -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; -} - -