使用axios校验环境是否连接互联网

This commit is contained in:
dinglili 2024-07-17 15:49:51 +08:00 committed by wangpenglong
parent 69f0518bd8
commit 3a10c9abfd
2 changed files with 11 additions and 26 deletions

View File

@ -586,7 +586,6 @@ class deployWindow {
if (this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1) {
this.custom_print("this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1");
if (this.onlineInstallTabArrayIndex == 0) {
//ipcRenderer.send("kylinide.installWizard.init", { type: "httpVerify" });
this.removeStepIndicator();
this.createStepIndicator(this.onlineInstallTabArray.length - 1, 0);
@ -594,6 +593,7 @@ class deployWindow {
let result = await ipcRenderer.invoke('kylinide.installWizard.init.httpVerify');
if (result === void 0) {
this.prevBtn!.disabled = false;
this.nextBtn!.disabled = false;
console.log("kylinide.installWizard.init.httpVerify result is void");
return;
}

View File

@ -29,7 +29,6 @@ import { Disposable } from 'vs/base/common/lifecycle';
import * as installUtils from 'vs/platform/issue/electron-main/installUtils';
import * as fs from 'fs';
import * as path from 'path';
import * as http from 'http';
import axios from "axios";
import { spawn, ChildProcess } from 'child_process';
import { AbortController } from "@azure/abort-controller";
@ -648,7 +647,7 @@ export class DeployMainService implements IDeployMainService {
{
type: "error",
title: "网络检查",
message: "网络异常,无法使用在线安装"
message: "网络连接异常,无法使用在线安装"
});
}
return void 0;
@ -1312,31 +1311,17 @@ export class DeployMainService implements IDeployMainService {
checkHttp() {
return new Promise((resolve, reject) => {
this.logger.info("检查网络联通情况");
const options = {
host: 'www.baidu.com',
port: 80,
path: '/',
};
const req = http.get(options, (res: any) => {
if (res.statusCode === 200) {
resolve(200);
this.logger.info("网络联通正常");
axios.get("https://www.gitee.com", { timeout: 5000 }).then(response => {
resolve(200);
}).catch(error => {
if (error.code === 'ECONNABORTED') {
reject(-1);
this.logger.error('网络请求验证超时');
} else {
reject(res.statusCode)
this.logger.info('无法访问网络');
reject(-1);
this.logger.error('网络连接发生错误:', error);
}
});
req.setTimeout(5000, () => {
reject(-1);
this.logger.error('网络请求验证超时');
});
req.on('error', (error) => {
reject(error);
this.logger.error('网络链接发生错误:', error);
});
req.end();
})
})
}