使用axios校验环境是否连接互联网
This commit is contained in:
parent
69f0518bd8
commit
3a10c9abfd
|
@ -586,7 +586,6 @@ class deployWindow {
|
||||||
if (this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1) {
|
if (this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1) {
|
||||||
this.custom_print("this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1");
|
this.custom_print("this.onlineInstallTabArrayIndex < this.onlineInstallTabArray.length - 1");
|
||||||
if (this.onlineInstallTabArrayIndex == 0) {
|
if (this.onlineInstallTabArrayIndex == 0) {
|
||||||
//ipcRenderer.send("kylinide.installWizard.init", { type: "httpVerify" });
|
|
||||||
this.removeStepIndicator();
|
this.removeStepIndicator();
|
||||||
this.createStepIndicator(this.onlineInstallTabArray.length - 1, 0);
|
this.createStepIndicator(this.onlineInstallTabArray.length - 1, 0);
|
||||||
|
|
||||||
|
@ -594,6 +593,7 @@ class deployWindow {
|
||||||
let result = await ipcRenderer.invoke('kylinide.installWizard.init.httpVerify');
|
let result = await ipcRenderer.invoke('kylinide.installWizard.init.httpVerify');
|
||||||
if (result === void 0) {
|
if (result === void 0) {
|
||||||
this.prevBtn!.disabled = false;
|
this.prevBtn!.disabled = false;
|
||||||
|
this.nextBtn!.disabled = false;
|
||||||
console.log("kylinide.installWizard.init.httpVerify result is void");
|
console.log("kylinide.installWizard.init.httpVerify result is void");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import { Disposable } from 'vs/base/common/lifecycle';
|
||||||
import * as installUtils from 'vs/platform/issue/electron-main/installUtils';
|
import * as installUtils from 'vs/platform/issue/electron-main/installUtils';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as http from 'http';
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { spawn, ChildProcess } from 'child_process';
|
import { spawn, ChildProcess } from 'child_process';
|
||||||
import { AbortController } from "@azure/abort-controller";
|
import { AbortController } from "@azure/abort-controller";
|
||||||
|
@ -648,7 +647,7 @@ export class DeployMainService implements IDeployMainService {
|
||||||
{
|
{
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "网络检查",
|
title: "网络检查",
|
||||||
message: "网络异常,无法使用在线安装"
|
message: "网络连接异常,无法使用在线安装"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
|
@ -1312,31 +1311,17 @@ export class DeployMainService implements IDeployMainService {
|
||||||
|
|
||||||
checkHttp() {
|
checkHttp() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.logger.info("检查网络联通情况");
|
axios.get("https://www.gitee.com", { timeout: 5000 }).then(response => {
|
||||||
const options = {
|
|
||||||
host: 'www.baidu.com',
|
|
||||||
port: 80,
|
|
||||||
path: '/',
|
|
||||||
};
|
|
||||||
const req = http.get(options, (res: any) => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
resolve(200);
|
resolve(200);
|
||||||
this.logger.info("网络联通正常");
|
}).catch(error => {
|
||||||
} else {
|
if (error.code === 'ECONNABORTED') {
|
||||||
reject(res.statusCode)
|
|
||||||
this.logger.info('无法访问网络');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
req.setTimeout(5000, () => {
|
|
||||||
reject(-1);
|
reject(-1);
|
||||||
this.logger.error('网络请求验证超时');
|
this.logger.error('网络请求验证超时');
|
||||||
});
|
} else {
|
||||||
req.on('error', (error) => {
|
reject(-1);
|
||||||
reject(error);
|
this.logger.error('网络连接发生错误:', error);
|
||||||
this.logger.error('网络链接发生错误:', error);
|
}
|
||||||
});
|
})
|
||||||
req.end();
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue