feat(firstOpenProject): be based on os and shell version to provide different commands that open project in remote env

This commit is contained in:
Levi Yan
2025-06-16 23:05:01 +08:00
parent b36feb764b
commit f0973280f4
5 changed files with 48 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import DSHome from './home';
import RemoteContainer, { openProjectWithoutLogging } from './remote-container';
import User from './user';
import DevstarAPIHandler from './devstar-api';
import * as os from 'os';
import * as utils from './utils';
export class DevStarExtension {
@@ -18,6 +19,16 @@ export class DevStarExtension {
this.remoteContainer = new RemoteContainer(this.user);
this.dsHome = new DSHome(context, this.user);
// 确定local系统是否为win如果是保存powershell版本
if (vscode.env.remoteName === undefined) {
if (os.platform() === 'win32') {
utils.powershellVersion()
.then(powershellVersion => {
this.context.globalState.update('powershellVersion', powershellVersion)
})
}
}
// support for open with vscode in web
const handler = vscode.window.registerUriHandler({
handleUri: async (uri: vscode.Uri) => {
@@ -45,11 +56,11 @@ export class DevStarExtension {
// 如果没有用户登录,则直接登录;
const res = await this.user.login(access_token, devstar_username)
if (res === 'ok') {
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path)
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
}
} else if (devstar_username === this.user.getUsernameFromLocal()) {
// 如果同用户已经登录,则忽略,直接打开项目
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path)
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
} else {
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
@@ -58,7 +69,7 @@ export class DevStarExtension {
// 如果没有用户登录,则直接登录;
const res = await this.user.login(access_token, devstar_username)
if (res === 'ok') {
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path)
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
}
} else if (selection === 'No') {
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
@@ -86,7 +97,7 @@ export class DevStarExtension {
const container_username = username;
const project_path = decodeURIComponent(path);
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path)
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
}
}
}