删除掉不必要的内容
This commit is contained in:
@@ -289,18 +289,6 @@ export default class RemoteContainer {
|
|||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 由于使用了 stdio: 'ignore',这些事件监听器不再需要
|
|
||||||
// sshProcess.stdout.on('data', (data: Buffer) => {
|
|
||||||
// console.log(`[SSH stdout] ${data.toString()}`);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// sshProcess.stderr.on('data', (data: Buffer) => {
|
|
||||||
// console.error(`[SSH stderr] ${data.toString()}`);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map
|
|
||||||
// 因为我们无法也不需要控制这些独立进程的生命周期
|
|
||||||
|
|
||||||
// 等待 SSH 连接建立
|
// 等待 SSH 连接建立
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
|
|||||||
102
src/utils.ts
102
src/utils.ts
@@ -1,12 +1,7 @@
|
|||||||
import * as http from 'http';
|
|
||||||
import * as https from 'https';
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
const {
|
|
||||||
generateKeyPairSync,
|
|
||||||
} = require('node:crypto')
|
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
@@ -23,36 +18,6 @@ export function isMacOS(): boolean {
|
|||||||
return os.platform() === 'darwin';
|
return os.platform() === 'darwin';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function fetch(url: string): Promise<string> {
|
|
||||||
// determine the library to use (based on the url protocol)
|
|
||||||
const lib = url.startsWith('https://') ? https : http;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
lib.get(url, (response) => {
|
|
||||||
// make sure the status code is 200
|
|
||||||
if (response.statusCode !== 200) {
|
|
||||||
reject(new Error(`Failed to load page, status code: ${response.statusCode}`));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let data = '';
|
|
||||||
response.on('data', (chunk) => {
|
|
||||||
data += chunk;
|
|
||||||
});
|
|
||||||
response.on('end', () => {
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
}).on('error', (err) => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Sleep = (ms: number) => {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getVsCodeCommitId(): Promise<string> {
|
export async function getVsCodeCommitId(): Promise<string> {
|
||||||
if (isLinux() || isMacOS()) {
|
if (isLinux() || isMacOS()) {
|
||||||
return new Promise<string>((resolve) => {
|
return new Promise<string>((resolve) => {
|
||||||
@@ -132,70 +97,3 @@ export async function powershellVersion(): Promise<string> {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 在远程环境下,通过执行本地命令来检测本地系统信息
|
|
||||||
* 不依赖 os.platform(),因为在远程环境下它返回的是远程系统类型
|
|
||||||
*/
|
|
||||||
export async function detectLocalSystemInfo(): Promise<{
|
|
||||||
isWindows: boolean;
|
|
||||||
isLinux: boolean;
|
|
||||||
isMac: boolean;
|
|
||||||
powershellVersion?: string;
|
|
||||||
}> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
reject(new Error('系统检测超时'));
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
// 尝试执行 PowerShell 命令来检测是否为 Windows
|
|
||||||
exec('powershell -Command "$PSVersionTable.PSVersion.ToString()"', (error, stdout, stderr) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
|
|
||||||
if (!error && stdout && !stderr) {
|
|
||||||
// PowerShell 命令成功执行,说明是 Windows 系统
|
|
||||||
resolve({
|
|
||||||
isWindows: true,
|
|
||||||
isLinux: false,
|
|
||||||
isMac: false,
|
|
||||||
powershellVersion: stdout.trim()
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// PowerShell 命令失败,尝试检测 Unix 系统类型
|
|
||||||
exec('uname -s', (unameError, unameStdout) => {
|
|
||||||
if (!unameError && unameStdout) {
|
|
||||||
const osType = unameStdout.trim();
|
|
||||||
resolve({
|
|
||||||
isWindows: false,
|
|
||||||
isLinux: osType === 'Linux',
|
|
||||||
isMac: osType === 'Darwin',
|
|
||||||
powershellVersion: undefined
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 无法检测,返回默认值
|
|
||||||
resolve({
|
|
||||||
isWindows: false,
|
|
||||||
isLinux: false,
|
|
||||||
isMac: false,
|
|
||||||
powershellVersion: undefined
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在远程环境下,通过本地终端实时检测 PowerShell 版本
|
|
||||||
* 这样可以确保获取到最准确的版本信息,而不依赖于 globalState
|
|
||||||
* @deprecated 使用 detectLocalSystemInfo 替代
|
|
||||||
*/
|
|
||||||
export async function detectLocalPowershellVersion(): Promise<string> {
|
|
||||||
try {
|
|
||||||
const systemInfo = await detectLocalSystemInfo();
|
|
||||||
return systemInfo.powershellVersion || '';
|
|
||||||
} catch (error) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user